blob: 91cbe6be3c4323a751209cdddea4879a954a3c69 [file] [log] [blame]
Rakesh Iyer3506f3f2016-10-19 23:58:48 -07001/*
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 */
16package com.android.car.systemupdater;
17
Nicholas Sauer2dc00462018-02-09 21:58:42 -080018import android.Manifest;
19import android.content.pm.PackageManager;
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070020import android.os.Bundle;
Nicholas Sauer2dc00462018-02-09 21:58:42 -080021import android.support.v4.app.ActivityCompat;
22import android.support.v4.content.ContextCompat;
Nicholas Sauer59eeada2018-01-31 16:40:37 -080023import android.support.v7.app.AppCompatActivity;
24import android.support.v7.widget.Toolbar;
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070025
26import java.io.File;
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070027
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070028/**
Nicholas Sauer59eeada2018-01-31 16:40:37 -080029 * Apply a system update using an ota package on internal or external storage.
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070030 */
Nicholas Sauerf4498752018-02-02 23:52:29 -080031public class SystemUpdaterActivity extends AppCompatActivity
32 implements DeviceListFragment.SystemUpdater {
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070033
Nicholas Sauer2dc00462018-02-09 21:58:42 -080034 private static final int STORAGE_PERMISSIONS_REQUEST_CODE = 0;
35 private static final String[] REQUIRED_STORAGE_PERMISSIONS = new String[]{
36 Manifest.permission.READ_EXTERNAL_STORAGE,
37 Manifest.permission.WRITE_EXTERNAL_STORAGE
38 };
39
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070040 @Override
41 protected void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
Nicholas Sauer2dc00462018-02-09 21:58:42 -080043
44 if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
45 != PackageManager.PERMISSION_GRANTED) {
46 ActivityCompat.requestPermissions(this, REQUIRED_STORAGE_PERMISSIONS,
47 STORAGE_PERMISSIONS_REQUEST_CODE);
48 }
49
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070050 setContentView(R.layout.activity_main);
Nicholas Sauerf4498752018-02-02 23:52:29 -080051 Toolbar toolbar = findViewById(R.id.toolbar);
Nicholas Sauer59eeada2018-01-31 16:40:37 -080052 setSupportActionBar(toolbar);
53
Nicholas Sauerf4498752018-02-02 23:52:29 -080054 if (savedInstanceState == null) {
55 DeviceListFragment fragment = new DeviceListFragment();
56 getSupportFragmentManager().beginTransaction()
57 .replace(R.id.device_container, fragment)
58 .commitNow();
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070059 }
60 }
61
62 @Override
Nicholas Sauer2dc00462018-02-09 21:58:42 -080063 public void onRequestPermissionsResult(int requestCode, String permissions[],
64 int[] grantResults) {
65 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
66 if (STORAGE_PERMISSIONS_REQUEST_CODE == requestCode) {
67 if (grantResults.length == 0) {
68 finish();
69 }
70 for (int grantResult : grantResults) {
71 if (grantResult != PackageManager.PERMISSION_GRANTED) {
72 finish();
73 }
74 }
75 }
76 }
77
78 @Override
Nicholas Sauer59eeada2018-01-31 16:40:37 -080079 public void applyUpdate(File file) {
Nicholas Sauerf4498752018-02-02 23:52:29 -080080 UpdateLayoutFragment fragment = UpdateLayoutFragment.getInstance(file);
81 getSupportFragmentManager().beginTransaction()
82 .replace(R.id.device_container, fragment)
83 .addToBackStack(null)
84 .commit();
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070085 }
Rakesh Iyer3506f3f2016-10-19 23:58:48 -070086}