Skip to content

Commit

Permalink
add toggle for special access to hardware accelerators by Google apps
Browse files Browse the repository at this point in the history
  • Loading branch information
muhomorr authored and thestinger committed Apr 10, 2023
1 parent c1d3b1e commit 9fafcc8
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
15 changes: 15 additions & 0 deletions res/values/strings_ext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,19 @@
<string name="remote_provisioning_enabled_standard_server">Enabled; standard server</string>
<string name="remote_provisioning_disabled">Disabled</string>

<string name="Google_apps_special_accelerator_access_title">Special access to hardware accelerators for Google apps</string>
<string name="Google_apps_special_accelerator_access_summary_granted">Access granted</string>
<string name="Google_apps_special_accelerator_access_summary_not_granted">Access not granted</string>
<string name="Google_apps_special_accelerator_access_main_switch">Grant special access to hardware accelerators to Google apps</string>
<string name="Google_apps_special_accelerator_access_footer">
"Some Google apps expect to be able to access hardware accelerators in a special, more capable way than regular apps do.

Examples of such apps:
• Google Camera
• Google Photos
• Google Recorder

This setting applies to all users on the device."
</string>

</resources>
6 changes: 6 additions & 0 deletions res/xml/special_access.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@
android:key="special_access_more"
android:title="@string/special_access_more"
settings:controller="com.android.settings.applications.specialaccess.MoreSpecialAccessPreferenceController" />

<Preference
android:key="Google_apps_special_accelerator_access"
android:title="@string/Google_apps_special_accelerator_access_title"
android:fragment="com.android.settings.applications.specialaccess.GoogleSpecialAcceleratorAccessFragment"
settings:controller="com.android.settings.applications.specialaccess.GoogleSpecialAcceleratorAccessPrefController" />
</PreferenceScreen>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.android.settings.applications.specialaccess;

import android.app.ActivityThread;
import android.ext.settings.BoolSetting;
import android.ext.settings.ExtSettings;
import android.os.RemoteException;

import com.android.internal.util.GoogleCameraUtils;
import com.android.settings.R;
import com.android.settings.ext.BoolSettingFragment;
import com.android.settingslib.widget.FooterPreference;

public class GoogleSpecialAcceleratorAccessFragment extends BoolSettingFragment {
private static final String TAG = GoogleSpecialAcceleratorAccessFragment.class.getSimpleName();

@Override
protected BoolSetting getSetting() {
return ExtSettings.ALLOW_GOOGLE_APPS_SPECIAL_ACCESS_TO_ACCELERATORS;
}

@Override
protected CharSequence getTitle() {
return resText(R.string.Google_apps_special_accelerator_access_title);
}

@Override
protected CharSequence getMainSwitchTitle() {
return resText(R.string.Google_apps_special_accelerator_access_main_switch);
}

@Override
protected void onMainSwitchChanged(boolean state) {
if (GoogleCameraUtils.isCustomSeInfoNeededForAccessToAccelerators(requireContext())) {
try {
ActivityThread.getPackageManager().updateSeInfo(GoogleCameraUtils.PACKAGE_NAME);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}

@Override
protected FooterPreference makeFooterPref(FooterPreference.Builder builder) {
return builder.setTitle(R.string.Google_apps_special_accelerator_access_footer).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.android.settings.applications.specialaccess;

import android.content.Context;
import android.ext.settings.ExtSettings;

import com.android.settings.R;
import com.android.settings.ext.BoolSettingFragmentPrefController;

public class GoogleSpecialAcceleratorAccessPrefController extends BoolSettingFragmentPrefController {

public GoogleSpecialAcceleratorAccessPrefController(Context ctx, String key) {
super(ctx, key, ExtSettings.ALLOW_GOOGLE_APPS_SPECIAL_ACCESS_TO_ACCELERATORS);
}

@Override
public int getAvailabilityStatus() {
if (!mContext.getResources().getBoolean(
com.android.internal.R.bool.config_Google_apps_can_have_special_access_to_accelerators)) {
return UNSUPPORTED_ON_DEVICE;
}

return super.getAvailabilityStatus();
}

@Override
protected CharSequence getSummaryOn() {
return resText(R.string.Google_apps_special_accelerator_access_summary_granted);
}

@Override
protected CharSequence getSummaryOff() {
return resText(R.string.Google_apps_special_accelerator_access_summary_not_granted);
}
}

0 comments on commit 9fafcc8

Please sign in to comment.