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.SettingsActivity; 24 import com.android.settingslib.AppItem; 25 26 /** 27 * Standalone activity used to launch {@link AppDataUsage} from a 28 * {@link Settings#ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS} intent. 29 */ 30 public class AppDataUsageActivity extends SettingsActivity { 31 32 private static final boolean DEBUG = false; 33 private static final String TAG = "AppDataUsageActivity"; 34 35 @Override onCreate(Bundle savedInstanceState)36 protected void onCreate(Bundle savedInstanceState) { 37 final Intent intent = getIntent(); 38 final String packageName = intent.getData().getSchemeSpecificPart(); 39 final PackageManager pm = getPackageManager(); 40 final int uid; 41 try { 42 uid = pm.getPackageUid(packageName, 0); 43 } catch (PackageManager.NameNotFoundException e) { 44 Log.w(TAG, "invalid package: " + packageName); 45 try { 46 // Activity lifecycle still requires calling onCreate() 47 super.onCreate(savedInstanceState); 48 } catch (Exception e2) { 49 // Ignore - most likely caused by SettingsActivity because of invalid fragment 50 if (DEBUG) Log.d(TAG, "onCreate() exception", e); 51 } finally { 52 finish(); 53 } 54 return; 55 } 56 if (DEBUG) Log.d(TAG, "Package: " + packageName + " UID: " + uid); 57 58 final Bundle args = new Bundle(); 59 final AppItem appItem = new AppItem(uid); 60 appItem.addUid(uid); 61 args.putParcelable(AppDataUsage.ARG_APP_ITEM, appItem); 62 intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); 63 intent.putExtra(EXTRA_SHOW_FRAGMENT, AppDataUsage.class.getName()); 64 65 super.onCreate(savedInstanceState); 66 } 67 68 @Override isValidFragment(String fragmentName)69 protected boolean isValidFragment(String fragmentName) { 70 return AppDataUsage.class.getName().equals(fragmentName); 71 } 72 } 73