Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 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 | |
Nicholas Sauer | 2dc0046 | 2018-02-09 21:58:42 -0800 | [diff] [blame^] | 18 | import android.Manifest; |
| 19 | import android.content.pm.PackageManager; |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Nicholas Sauer | 2dc0046 | 2018-02-09 21:58:42 -0800 | [diff] [blame^] | 21 | import android.support.v4.app.ActivityCompat; |
| 22 | import android.support.v4.content.ContextCompat; |
Nicholas Sauer | 59eeada | 2018-01-31 16:40:37 -0800 | [diff] [blame] | 23 | import android.support.v7.app.AppCompatActivity; |
| 24 | import android.support.v7.widget.Toolbar; |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 25 | |
| 26 | import java.io.File; |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 27 | |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 28 | /** |
Nicholas Sauer | 59eeada | 2018-01-31 16:40:37 -0800 | [diff] [blame] | 29 | * Apply a system update using an ota package on internal or external storage. |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 30 | */ |
Nicholas Sauer | f449875 | 2018-02-02 23:52:29 -0800 | [diff] [blame] | 31 | public class SystemUpdaterActivity extends AppCompatActivity |
| 32 | implements DeviceListFragment.SystemUpdater { |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 33 | |
Nicholas Sauer | 2dc0046 | 2018-02-09 21:58:42 -0800 | [diff] [blame^] | 34 | 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 Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 40 | @Override |
| 41 | protected void onCreate(Bundle savedInstanceState) { |
| 42 | super.onCreate(savedInstanceState); |
Nicholas Sauer | 2dc0046 | 2018-02-09 21:58:42 -0800 | [diff] [blame^] | 43 | |
| 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 Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 50 | setContentView(R.layout.activity_main); |
Nicholas Sauer | f449875 | 2018-02-02 23:52:29 -0800 | [diff] [blame] | 51 | Toolbar toolbar = findViewById(R.id.toolbar); |
Nicholas Sauer | 59eeada | 2018-01-31 16:40:37 -0800 | [diff] [blame] | 52 | setSupportActionBar(toolbar); |
| 53 | |
Nicholas Sauer | f449875 | 2018-02-02 23:52:29 -0800 | [diff] [blame] | 54 | if (savedInstanceState == null) { |
| 55 | DeviceListFragment fragment = new DeviceListFragment(); |
| 56 | getSupportFragmentManager().beginTransaction() |
| 57 | .replace(R.id.device_container, fragment) |
| 58 | .commitNow(); |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
Nicholas Sauer | 2dc0046 | 2018-02-09 21:58:42 -0800 | [diff] [blame^] | 63 | 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 Sauer | 59eeada | 2018-01-31 16:40:37 -0800 | [diff] [blame] | 79 | public void applyUpdate(File file) { |
Nicholas Sauer | f449875 | 2018-02-02 23:52:29 -0800 | [diff] [blame] | 80 | UpdateLayoutFragment fragment = UpdateLayoutFragment.getInstance(file); |
| 81 | getSupportFragmentManager().beginTransaction() |
| 82 | .replace(R.id.device_container, fragment) |
| 83 | .addToBackStack(null) |
| 84 | .commit(); |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 85 | } |
Rakesh Iyer | 3506f3f | 2016-10-19 23:58:48 -0700 | [diff] [blame] | 86 | } |