• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.settings.datausage;
16 
17 import android.content.Intent;
18 import android.content.pm.PackageManager;
19 import android.os.Bundle;
20 import android.provider.Settings;
21 import android.util.Log;
22 
23 import com.android.settings.R;
24 import com.android.settings.SettingsActivity;
25 import com.android.settingslib.AppItem;
26 
27 /**
28  * Standalone activity used to launch {@link AppDataUsage} from a
29  * {@link Settings#ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS} intent.
30  */
31 public class AppDataUsageActivity extends SettingsActivity {
32 
33     private static final boolean DEBUG = false;
34     private static final String TAG = "AppDataUsageActivity";
35 
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         final Intent intent = getIntent();
39         final String packageName = intent.getData().getSchemeSpecificPart();
40         final PackageManager pm = getPackageManager();
41         final int uid;
42         try {
43             uid = pm.getPackageUid(packageName, 0);
44         } catch (PackageManager.NameNotFoundException e) {
45             Log.w(TAG, "invalid package: " + packageName);
46             try {
47                 // Activity lifecycle still requires calling onCreate()
48                 super.onCreate(savedInstanceState);
49             } catch (Exception e2) {
50                 // Ignore - most likely caused by SettingsActivity because of invalid fragment
51                 if (DEBUG) Log.d(TAG, "onCreate() exception", e);
52             } finally {
53                 finish();
54             }
55             return;
56         }
57         if (DEBUG) Log.d(TAG, "Package: " + packageName + " UID: " + uid);
58 
59         final Bundle args = new Bundle();
60         final AppItem appItem = new AppItem(uid);
61         appItem.addUid(uid);
62         args.putParcelable(AppDataUsage.ARG_APP_ITEM, appItem);
63         intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
64         intent.putExtra(EXTRA_SHOW_FRAGMENT, AppDataUsage.class.getName());
65         intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.data_usage_app_summary_title);
66 
67         super.onCreate(savedInstanceState);
68     }
69 
70     @Override
isValidFragment(String fragmentName)71     protected boolean isValidFragment(String fragmentName) {
72         return super.isValidFragment(fragmentName)
73                 || AppDataUsage.class.getName().equals(fragmentName);
74     }
75 }
76