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