1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.car.systemupdater; 17 18 import static com.android.car.systemupdater.UpdateLayoutFragment.EXTRA_RESUME_UPDATE; 19 20 import android.os.Bundle; 21 import android.view.MenuItem; 22 23 import androidx.appcompat.app.AppCompatActivity; 24 25 import com.android.car.ui.core.CarUi; 26 import com.android.car.ui.toolbar.Toolbar; 27 import com.android.car.ui.toolbar.ToolbarController; 28 29 import java.io.File; 30 31 /** 32 * Apply a system update using an ota package on internal or external storage. 33 */ 34 public class SystemUpdaterActivity extends AppCompatActivity 35 implements DeviceListFragment.SystemUpdater { 36 37 private static final String FRAGMENT_TAG = "FRAGMENT_TAG"; 38 39 @Override onCreate(Bundle savedInstanceState)40 protected void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 43 setContentView(R.layout.activity_main); 44 45 ToolbarController toolbar = CarUi.requireToolbar(this); 46 toolbar.setTitle(getString(R.string.title)); 47 toolbar.setState(Toolbar.State.SUBPAGE); 48 49 if (savedInstanceState == null) { 50 Bundle intentExtras = getIntent().getExtras(); 51 if (intentExtras != null && intentExtras.getBoolean(EXTRA_RESUME_UPDATE)) { 52 UpdateLayoutFragment fragment = UpdateLayoutFragment.newResumedInstance(); 53 getSupportFragmentManager().beginTransaction() 54 .replace(R.id.device_container, fragment, FRAGMENT_TAG) 55 .commitNow(); 56 } else { 57 DeviceListFragment fragment = new DeviceListFragment(); 58 getSupportFragmentManager().beginTransaction() 59 .replace(R.id.device_container, fragment, FRAGMENT_TAG) 60 .commitNow(); 61 } 62 } 63 } 64 65 @Override onOptionsItemSelected(MenuItem item)66 public boolean onOptionsItemSelected(MenuItem item) { 67 if (item.getItemId() == android.R.id.home) { 68 UpFragment upFragment = 69 (UpFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG); 70 if (!upFragment.goUp()) { 71 onBackPressed(); 72 } 73 return true; 74 } 75 return super.onOptionsItemSelected(item); 76 } 77 78 @Override applyUpdate(File file)79 public void applyUpdate(File file) { 80 UpdateLayoutFragment fragment = UpdateLayoutFragment.getInstance(file); 81 getSupportFragmentManager().beginTransaction() 82 .replace(R.id.device_container, fragment, FRAGMENT_TAG) 83 .addToBackStack(null) 84 .commit(); 85 } 86 } 87