Home | History | Annotate | Download | only in ui
      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.Fragment;
     20 import android.content.Intent;
     21 import android.os.Bundle;
     22 import android.util.Log;
     23 
     24 import com.android.packageinstaller.permission.ui.wear.AppPermissionsFragmentWear;
     25 import com.android.packageinstaller.DeviceUtils;
     26 
     27 public final class ManagePermissionsActivity extends OverlayTouchActivity {
     28     private static final String LOG_TAG = "ManagePermissionsActivity";
     29 
     30     @Override
     31     public void onCreate(Bundle savedInstanceState) {
     32         super.onCreate(savedInstanceState);
     33 
     34         if (savedInstanceState != null) {
     35             return;
     36         }
     37 
     38         Fragment fragment;
     39         String action = getIntent().getAction();
     40 
     41         switch (action) {
     42             case Intent.ACTION_MANAGE_PERMISSIONS: {
     43                 if (DeviceUtils.isTelevision(this)) {
     44                     fragment = com.android.packageinstaller.permission.ui.television
     45                             .ManagePermissionsFragment.newInstance();
     46                 } else {
     47                     fragment = com.android.packageinstaller.permission.ui.handheld
     48                             .ManagePermissionsFragment.newInstance();
     49                 }
     50             } break;
     51 
     52             case Intent.ACTION_MANAGE_APP_PERMISSIONS: {
     53                 String packageName = getIntent().getStringExtra(Intent.EXTRA_PACKAGE_NAME);
     54                 if (packageName == null) {
     55                     Log.i(LOG_TAG, "Missing mandatory argument EXTRA_PACKAGE_NAME");
     56                     finish();
     57                     return;
     58                 }
     59                 if (DeviceUtils.isWear(this)) {
     60                     fragment = AppPermissionsFragmentWear.newInstance(packageName);
     61                 } else if (DeviceUtils.isTelevision(this)) {
     62                     fragment = com.android.packageinstaller.permission.ui.television
     63                             .AppPermissionsFragment.newInstance(packageName);
     64                 } else {
     65                     fragment = com.android.packageinstaller.permission.ui.handheld
     66                             .AppPermissionsFragment.newInstance(packageName);
     67                 }
     68             } break;
     69 
     70             case Intent.ACTION_MANAGE_PERMISSION_APPS: {
     71                 String permissionName = getIntent().getStringExtra(Intent.EXTRA_PERMISSION_NAME);
     72                 if (permissionName == null) {
     73                     Log.i(LOG_TAG, "Missing mandatory argument EXTRA_PERMISSION_NAME");
     74                     finish();
     75                     return;
     76                 }
     77                 if (DeviceUtils.isTelevision(this)) {
     78                     fragment = com.android.packageinstaller.permission.ui.television
     79                             .PermissionAppsFragment.newInstance(permissionName);
     80                 } else {
     81                     fragment = com.android.packageinstaller.permission.ui.handheld
     82                             .PermissionAppsFragment.newInstance(permissionName);
     83                 }
     84             } break;
     85 
     86             default: {
     87                 Log.w(LOG_TAG, "Unrecognized action " + action);
     88                 finish();
     89                 return;
     90             }
     91         }
     92 
     93         getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
     94     }
     95 }
     96