blob: 3b3933b7db10fe6386cd058de723894375b8221e [file] [log] [blame]
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +08001/*
2 * Copyright (C) 2019 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
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +080017package com.android.dynsystem;
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080018
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080019import android.app.Activity;
20import android.app.KeyguardManager;
21import android.content.Context;
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080022import android.content.Intent;
Po-Chien Hsuehc51cf0f2019-03-21 17:16:06 +080023import android.net.Uri;
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080024import android.os.Bundle;
Po-Chien Hsueh4167b422019-04-01 11:26:18 +080025import android.os.SystemProperties;
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080026import android.os.UserHandle;
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +080027import android.os.image.DynamicSystemClient;
Po-Chien Hsueh4167b422019-04-01 11:26:18 +080028import android.util.FeatureFlagUtils;
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080029import android.util.Log;
30
31
32/**
33 * This Activity starts KeyguardManager and ask the user to confirm
34 * before any installation request. If the device is not protected by
35 * a password, it approves the request by default.
36 */
37public class VerificationActivity extends Activity {
38
39 private static final String TAG = "VerificationActivity";
40
41 private static final int REQUEST_CODE = 1;
42
43 // For install request verification
44 private static String sVerifiedUrl;
45
46
47 @Override
48 protected void onCreate(Bundle savedInstanceState) {
49 super.onCreate(savedInstanceState);
50
Po-Chien Hsueh4167b422019-04-01 11:26:18 +080051 if (!featureFlagEnabled()) {
52 Log.w(TAG, FeatureFlagUtils.DYNAMIC_SYSTEM + " not enabled; activity aborted.");
53 finish();
54 return;
55 }
56
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080057 KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
58
59 if (km != null) {
60 String title = getString(R.string.keyguard_title);
61 String description = getString(R.string.keyguard_description);
62 Intent intent = km.createConfirmDeviceCredentialIntent(title, description);
63
64 if (intent == null) {
65 Log.d(TAG, "This device is not protected by a password/pin");
66 startInstallationService();
67 finish();
68 } else {
69 startActivityForResult(intent, REQUEST_CODE);
70 }
71 } else {
72 finish();
73 }
74 }
75
76 @Override
77 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
78 if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
79 startInstallationService();
80 }
81
82 finish();
83 }
84
85 private void startInstallationService() {
86 // retrieve data from calling intent
87 Intent callingIntent = getIntent();
Po-Chien Hsuehc51cf0f2019-03-21 17:16:06 +080088 Uri url = callingIntent.getData();
Yo Chianga69bb072019-12-18 15:58:02 +080089 Bundle extras = callingIntent.getExtras();
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080090
Po-Chien Hsuehc51cf0f2019-03-21 17:16:06 +080091 sVerifiedUrl = url.toString();
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080092
93 // start service
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +080094 Intent intent = new Intent(this, DynamicSystemInstallationService.class);
Po-Chien Hsuehc51cf0f2019-03-21 17:16:06 +080095 intent.setData(url);
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +080096 intent.setAction(DynamicSystemClient.ACTION_START_INSTALL);
Yo Chianga69bb072019-12-18 15:58:02 +080097 intent.putExtras(extras);
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +080098
99 Log.d(TAG, "Starting Installation Service");
100 startServiceAsUser(intent, UserHandle.SYSTEM);
101 }
102
Po-Chien Hsueh4167b422019-04-01 11:26:18 +0800103 private boolean featureFlagEnabled() {
104 return SystemProperties.getBoolean(
105 FeatureFlagUtils.PERSIST_PREFIX + FeatureFlagUtils.DYNAMIC_SYSTEM, false);
106 }
107
Po-Chien Hsueh64aa7822019-01-12 00:40:02 +0800108 static boolean isVerified(String url) {
109 return sVerifiedUrl != null && sVerifiedUrl.equals(url);
110 }
111}