Merge Screen Attention and Screen timeout Settings.
Bug: 155051311 Test: atest Change-Id: I6f6ee52618eab629a41b28982be32ead5f9ba08d
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
* 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
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.display;
|
||||
@@ -20,44 +20,53 @@ import static com.android.settings.display.AdaptiveSleepPreferenceController.has
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class AdaptiveSleepPermissionPreferenceController extends BasePreferenceController {
|
||||
final static String PREF_NAME = "adaptive_sleep_permission";
|
||||
private final Intent mIntent;
|
||||
/**
|
||||
* The controller of Screen attention's permission warning preference. The preference appears when
|
||||
* the camera permission is missing for Screen Attention feature.
|
||||
*/
|
||||
public class AdaptiveSleepPermissionPreferenceController {
|
||||
@VisibleForTesting
|
||||
Preference mPreference;
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
public AdaptiveSleepPermissionPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
public AdaptiveSleepPermissionPreferenceController(Context context) {
|
||||
final String packageName = context.getPackageManager().getAttentionServicePackageName();
|
||||
mIntent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
mIntent.setData(Uri.parse("package:" + packageName));
|
||||
}
|
||||
|
||||
@Override
|
||||
@AvailabilityStatus
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
||||
mContext.startActivity(mIntent);
|
||||
mPackageManager = context.getPackageManager();
|
||||
final Intent intent = new Intent(
|
||||
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse("package:" + packageName));
|
||||
mPreference = new Preference(context);
|
||||
mPreference.setTitle(R.string.adaptive_sleep_title_no_permission);
|
||||
mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission);
|
||||
mPreference.setIcon(R.drawable.ic_info_outline_24);
|
||||
mPreference.setOnPreferenceClickListener(p -> {
|
||||
context.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (TextUtils.equals(getPreferenceKey(), preference.getKey())) {
|
||||
preference.setVisible(!hasSufficientPermission(mContext.getPackageManager()));
|
||||
/**
|
||||
* Adds the controlled preference to the provided preference screen.
|
||||
*/
|
||||
public void addToScreen(PreferenceScreen screen) {
|
||||
if (!hasSufficientPermission(mPackageManager)) {
|
||||
screen.addPreference(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes the visibility of the preference.
|
||||
*/
|
||||
public void updateVisibility() {
|
||||
mPreference.setVisible(!hasSufficientPermission(mPackageManager));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user