1 /* 2 * Copyright (C) 2019 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.settings.fuelgauge; 18 19 import static com.android.settings.fuelgauge.AdvancedPowerUsageDetail.EXTRA_PACKAGE_NAME; 20 import static com.android.settings.fuelgauge.AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_PERCENT; 21 import static com.android.settings.fuelgauge.AdvancedPowerUsageDetail.EXTRA_UID; 22 23 import android.app.settings.SettingsEnums; 24 import android.content.Intent; 25 import android.content.pm.PackageManager; 26 import android.net.Uri; 27 import android.os.Bundle; 28 import android.util.Log; 29 30 import androidx.appcompat.app.AppCompatActivity; 31 32 import com.android.settings.core.SubSettingLauncher; 33 import com.android.settings.fuelgauge.AdvancedPowerUsageDetail; 34 import com.android.settings.R; 35 import com.android.settings.Utils; 36 37 /** 38 * Trampoline activity for launching the {@link AdvancedPowerUsageDetail} fragment. 39 */ 40 public class AdvancedPowerUsageDetailActivity extends AppCompatActivity { 41 42 private static final String TAG = "AdvancedPowerDetailActivity"; 43 44 @Override onCreate(Bundle savedInstanceState)45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 final Intent intent = getIntent(); 48 final Uri data = intent == null ? null : intent.getData(); 49 final String packageName = data == null ? null : data.getSchemeSpecificPart(); 50 if (packageName != null) { 51 final Bundle args = new Bundle(4); 52 final PackageManager packageManager = getPackageManager(); 53 args.putString(EXTRA_PACKAGE_NAME, packageName); 54 args.putString(EXTRA_POWER_USAGE_PERCENT, Utils.formatPercentage(0)); 55 56 if (intent.getBooleanExtra("request_ignore_background_restriction", false)) { 57 args.putString(":settings:fragment_args_key", "background_activity"); 58 } 59 60 try { 61 args.putInt(EXTRA_UID, packageManager.getPackageUid(packageName, 0 /* no flag */)); 62 } catch (PackageManager.NameNotFoundException e) { 63 Log.w(TAG, "Cannot find package: " + packageName, e); 64 } 65 66 new SubSettingLauncher(this) 67 .setDestination(AdvancedPowerUsageDetail.class.getName()) 68 .setTitleRes(R.string.battery_details_title) 69 .setArguments(args) 70 .setSourceMetricsCategory(SettingsEnums.APPLICATIONS_INSTALLED_APP_DETAILS) 71 .launch(); 72 } 73 74 finish(); 75 } 76 } 77