• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 
17 package com.android.internal.telephony.uicc;
18 
19 import android.app.Activity;
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.res.Resources;
24 import android.os.Bundle;
25 import android.os.UserHandle;
26 import android.provider.Settings;
27 import android.text.TextUtils;
28 import android.util.Log;
29 
30 import java.util.concurrent.TimeUnit;
31 
32 /**
33  * Trampoline activity used to start the full screen dialog that is shown when a SIM is inserted
34  * and requires a carrier app download
35  */
36 public class InstallCarrierAppTrampolineActivity extends Activity {
37     private static final String LOG_TAG = "CarrierAppInstall";
38     private static final int INSTALL_CARRIER_APP_DIALOG_REQUEST = 1;
39 
40     // TODO(b/73648962): Move DOWNLOAD_RESULT and CARRIER_NAME to a shared location
41     /**
42      * This must remain in sync with
43      * {@link com.android.simappdialog.InstallCarrierAppActivity#DOWNLOAD_RESULT}
44      */
45     private static final int DOWNLOAD_RESULT = 2;
46 
47     /**
48      * This must remain in sync with
49      * {@link com.android.simappdialog.InstallCarrierAppActivity#BUNDLE_KEY_CARRIER_NAME}
50      */
51     private static final String CARRIER_NAME = "carrier_name";
52 
53     /** Bundle key for the name of the package to be downloaded */
54     private static final String BUNDLE_KEY_PACKAGE_NAME = "package_name";
55 
56     /** Returns intent used to start this activity */
get(Context context, String packageName)57     public static Intent get(Context context, String packageName) {
58         Intent intent = new Intent(context, InstallCarrierAppTrampolineActivity.class);
59         intent.putExtra(BUNDLE_KEY_PACKAGE_NAME, packageName);
60         return intent;
61     }
62 
63     private String mPackageName;
64 
65     @Override
onCreate(Bundle savedInstanceState)66     protected void onCreate(Bundle savedInstanceState) {
67         super.onCreate(savedInstanceState);
68         Intent intent = getIntent();
69         if (intent != null) {
70             mPackageName = intent.getStringExtra(BUNDLE_KEY_PACKAGE_NAME);
71         }
72 
73         // If this is the first activity creation, show notification after delay regardless of
74         // result code, but only if the app is not installed.
75         if (savedInstanceState == null) {
76             long sleepTimeMillis = Settings.Global.getLong(getContentResolver(),
77                     Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
78                     TimeUnit.HOURS.toMillis(24));
79             Log.d(LOG_TAG, "Sleeping carrier app install notification for : " + sleepTimeMillis
80                     + " millis");
81             InstallCarrierAppUtils.showNotificationIfNotInstalledDelayed(
82                     this,
83                     mPackageName,
84                     sleepTimeMillis);
85         }
86 
87         // Display dialog activity if available
88         Intent showDialogIntent = new Intent();
89         ComponentName dialogComponentName = ComponentName.unflattenFromString(
90                 Resources.getSystem().getString(
91                         com.android.internal.R.string.config_carrierAppInstallDialogComponent));
92         showDialogIntent.setComponent(dialogComponentName);
93         String appName = InstallCarrierAppUtils.getAppNameFromPackageName(this, mPackageName);
94         if (!TextUtils.isEmpty(appName)) {
95             showDialogIntent.putExtra(CARRIER_NAME, appName);
96         }
97 
98         if (showDialogIntent.resolveActivity(getPackageManager()) == null) {
99             Log.d(LOG_TAG, "Could not resolve activity for installing the carrier app");
100             finishNoAnimation();
101         } else {
102             startActivityForResult(showDialogIntent, INSTALL_CARRIER_APP_DIALOG_REQUEST);
103         }
104     }
105 
106     @Override
onActivityResult(int requestCode, int resultCode, Intent data)107     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
108         super.onActivityResult(requestCode, resultCode, data);
109         if (requestCode == INSTALL_CARRIER_APP_DIALOG_REQUEST) {
110             if (resultCode == DOWNLOAD_RESULT) {
111                 startActivityAsUser(InstallCarrierAppUtils.getPlayStoreIntent(mPackageName),
112                         UserHandle.CURRENT);
113             }
114             finishNoAnimation();
115         }
116     }
117 
finishNoAnimation()118     private void finishNoAnimation() {
119         finish();
120         overridePendingTransition(0, 0);
121     }
122 }
123