Add Device Diagnostics to Settings.
The new option will only appear if (1) the flag is enabled and (2) DeviceDiagnostics.apk is landed on the device (which it is by default on AOSP). Bug: 309886423 Test: Build AOSP Pixel and launch Settings Change-Id: If01d231664a301ff289d4da61445bf65a7506fdb
This commit is contained in:
9
aconfig/settings_device_diagnostics_declarations.aconfig
Normal file
9
aconfig/settings_device_diagnostics_declarations.aconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
package: "com.android.settings.flags"
|
||||
container: "system_ext"
|
||||
|
||||
flag {
|
||||
name: "enable_device_diagnostics_in_settings"
|
||||
namespace: "phoenix"
|
||||
description: "Enable the Device Diagnostics app in Settings"
|
||||
bug: "309886423"
|
||||
}
|
10
res/drawable/ic_device_diagnostics.xml
Normal file
10
res/drawable/ic_device_diagnostics.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M320,760h320v-80L320,680v80ZM320,640h320v-80L320,560v80ZM480,492q66,-60 113,-106.5t47,-97.5q0,-36 -26,-62t-62,-26q-21,0 -40.5,8.5T480,232q-12,-15 -31.5,-23.5T408,200q-36,0 -62,26t-26,62q0,51 45.5,96T480,492ZM720,880L240,880q-33,0 -56.5,-23.5T160,800v-640q0,-33 23.5,-56.5T240,80h480q33,0 56.5,23.5T800,160v640q0,33 -23.5,56.5T720,880ZM240,800h480v-640L240,160v640ZM240,800v-640,640Z"
|
||||
android:fillColor="#FFFFFFFF"/>
|
||||
</vector>
|
@@ -836,4 +836,7 @@
|
||||
|
||||
<!-- The Activity intent to trigger to launch time-related feedback. -->
|
||||
<string name="config_time_feedback_intent_uri" translatable="false" />
|
||||
|
||||
<!-- Package name for diagnostics app. -->
|
||||
<string name="config_device_diagnostics_package_name" translatable="false">com.android.devicediagnostics</string>
|
||||
</resources>
|
||||
|
@@ -13258,4 +13258,9 @@
|
||||
|
||||
<!--Title for Sync Across Devices category-->
|
||||
<string name="sync_across_devices_title">Sync across devices</string>
|
||||
|
||||
<!-- Device Diagnostics -->
|
||||
|
||||
<!-- Title for System dashboard fragment -->
|
||||
<string name="device_diagnostics_title">Device diagnostics</string>
|
||||
</resources>
|
||||
|
@@ -97,6 +97,13 @@
|
||||
android:order="-40"
|
||||
settings:controller="com.android.settings.system.DeveloperOptionsController"/>
|
||||
|
||||
<Preference
|
||||
android:key="device_diagnostics"
|
||||
android:title="@string/device_diagnostics_title"
|
||||
android:order="-35"
|
||||
android:icon="@drawable/ic_device_diagnostics"
|
||||
settings:controller="com.android.settings.system.DeviceDiagnosticsPreferenceController"/>
|
||||
|
||||
<Preference
|
||||
android:key="reset_dashboard"
|
||||
android:title="@string/reset_dashboard_title"
|
||||
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.system
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ResolveInfo
|
||||
|
||||
import androidx.preference.Preference
|
||||
|
||||
import com.android.settings.R
|
||||
import com.android.settings.core.BasePreferenceController
|
||||
import com.android.settings.flags.Flags
|
||||
|
||||
class DeviceDiagnosticsPreferenceController(context: Context, preferenceKey: String) :
|
||||
BasePreferenceController(context, preferenceKey) {
|
||||
|
||||
override fun getAvailabilityStatus(): Int {
|
||||
if (!Flags.enableDeviceDiagnosticsInSettings()) {
|
||||
return UNSUPPORTED_ON_DEVICE
|
||||
}
|
||||
if (getIntent() == null) {
|
||||
return UNSUPPORTED_ON_DEVICE
|
||||
}
|
||||
return AVAILABLE
|
||||
}
|
||||
|
||||
override fun handlePreferenceTreeClick(preference: Preference): Boolean {
|
||||
if (preferenceKey != preference.key) {
|
||||
return false
|
||||
}
|
||||
|
||||
val intent = getIntent()
|
||||
if (intent == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
preference.getContext().startActivity(intent)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun getIntent(): Intent? {
|
||||
val intent = Intent(Intent.ACTION_MAIN)
|
||||
|
||||
val packageName = mContext.getResources().getString(
|
||||
R.string.config_device_diagnostics_package_name)
|
||||
intent.setPackage(packageName)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
return intent
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user