blob: f61a16f3defe035f5622a7baf474e6be1fc4b05f [file] [log] [blame]
/*
* Copyright (C) 2019 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.car.settings.applications.defaultapps;
import android.car.drivingstate.CarUxRestrictions;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import androidx.annotation.Nullable;
import com.android.car.settings.common.ButtonPreference;
import com.android.car.settings.common.FragmentController;
import com.android.settingslib.applications.DefaultAppInfo;
/**
* Base preference which handles the logic to display the currently selected default app as well as
* an option to navigate to the settings of the selected default app.
*/
public abstract class DefaultAppsPickerEntryBasePreferenceController extends
DefaultAppEntryBasePreferenceController<ButtonPreference> {
public DefaultAppsPickerEntryBasePreferenceController(Context context, String preferenceKey,
FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
super(context, preferenceKey, fragmentController, uxRestrictions);
}
@Override
protected Class<ButtonPreference> getPreferenceType() {
return ButtonPreference.class;
}
@Override
protected void updateState(ButtonPreference preference) {
super.updateState(preference);
Intent intent = getSettingIntent(getCurrentDefaultAppInfo());
boolean isSafeIntent = false;
if (intent != null) {
ActivityInfo info = intent.resolveActivityInfo(
getContext().getPackageManager(), intent.getFlags());
// If activity exists and is visible to Car Settings, allow intenting to the activity.
if (info != null && info.exported) {
isSafeIntent = true;
}
}
preference.showAction(isSafeIntent);
if (isSafeIntent) {
// Use startActivityForResult because some apps need to check the identity of the
// caller.
preference.setOnButtonClickListener(p -> getContext().startActivityForResult(
getContext().getBasePackageName(),
intent,
/* requestCode= */ 0,
/* options= */ null
));
}
}
/**
* Returns an optional intent that will be launched when clicking the secondary action icon.
*/
@Nullable
protected Intent getSettingIntent(@Nullable DefaultAppInfo info) {
return null;
}
}