• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.packageinstaller.permission.ui;
18 
19 import android.app.Activity;
20 
21 import android.app.Fragment;
22 import android.content.Intent;
23 import android.content.pm.PackageInfo;
24 import android.content.pm.PackageManager;
25 import android.os.Bundle;
26 import android.text.TextUtils;
27 import com.android.packageinstaller.DeviceUtils;
28 import com.android.packageinstaller.R;
29 import com.android.packageinstaller.permission.ui.handheld.ReviewPermissionsFragment;
30 import com.android.packageinstaller.permission.ui.ConfirmActionDialogFragment.OnActionConfirmedListener;
31 import com.android.packageinstaller.permission.ui.wear.ReviewPermissionsWearFragment;
32 
33 public final class ReviewPermissionsActivity extends Activity
34         implements OnActionConfirmedListener {
35 
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39 
40         PackageInfo packageInfo = getTargetPackageInfo();
41         if (packageInfo == null) {
42             finish();
43             return;
44         }
45 
46         if (DeviceUtils.isWear(this)) {
47             Fragment fragment = ReviewPermissionsWearFragment.newInstance(packageInfo);
48             getFragmentManager().beginTransaction()
49                     .replace(android.R.id.content, fragment).commit();
50         } else {
51             setContentView(R.layout.review_permissions);
52             if (getFragmentManager().findFragmentById(R.id.preferences_frame) == null) {
53                 getFragmentManager().beginTransaction().add(R.id.preferences_frame,
54                         ReviewPermissionsFragment.newInstance(packageInfo)).commit();
55             }
56         }
57     }
58 
59     @Override
onActionConfirmed(String action)60     public void onActionConfirmed(String action) {
61         Fragment fragment = getFragmentManager().findFragmentById(R.id.preferences_frame);
62         if (fragment instanceof OnActionConfirmedListener) {
63             ((OnActionConfirmedListener) fragment).onActionConfirmed(action);
64         }
65     }
66 
getTargetPackageInfo()67     private PackageInfo getTargetPackageInfo() {
68         String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
69         if (TextUtils.isEmpty(packageName)) {
70             return null;
71         }
72         try {
73             return getPackageManager().getPackageInfo(packageName,
74                     PackageManager.GET_PERMISSIONS);
75         } catch (PackageManager.NameNotFoundException e) {
76             return null;
77         }
78     }
79 }
80