Skip to content

Commit 1c47cef

Browse files
muhomorrthestinger
authored andcommitted
add toggle for special access to hardware accelerators by Google apps
1 parent 4ad6aa2 commit 1c47cef

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

res/values/strings_ext.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,19 @@
3333
<string name="remote_provisioning_enabled_standard_server">Enabled; standard server</string>
3434
<string name="remote_provisioning_disabled">Disabled</string>
3535

36+
<string name="Google_apps_special_accelerator_access_title">Special access to hardware accelerators for Google apps</string>
37+
<string name="Google_apps_special_accelerator_access_summary_granted">Access granted</string>
38+
<string name="Google_apps_special_accelerator_access_summary_not_granted">Access not granted</string>
39+
<string name="Google_apps_special_accelerator_access_main_switch">Grant special access to hardware accelerators to Google apps</string>
40+
<string name="Google_apps_special_accelerator_access_footer">
41+
"Some Google apps expect to be able to access hardware accelerators in a special, more capable way than regular apps do.
42+
43+
Examples of such apps:
44+
• Google Camera
45+
• Google Photos
46+
• Google Recorder
47+
48+
This setting applies to all users on the device."
49+
</string>
50+
3651
</resources>

res/xml/special_access.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,10 @@
167167
android:key="special_access_more"
168168
android:title="@string/special_access_more"
169169
settings:controller="com.android.settings.applications.specialaccess.MoreSpecialAccessPreferenceController" />
170+
171+
<Preference
172+
android:key="Google_apps_special_accelerator_access"
173+
android:title="@string/Google_apps_special_accelerator_access_title"
174+
android:fragment="com.android.settings.applications.specialaccess.GoogleSpecialAcceleratorAccessFragment"
175+
settings:controller="com.android.settings.applications.specialaccess.GoogleSpecialAcceleratorAccessPrefController" />
170176
</PreferenceScreen>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.android.settings.applications.specialaccess;
2+
3+
import android.app.ActivityThread;
4+
import android.ext.settings.BoolSetting;
5+
import android.ext.settings.ExtSettings;
6+
import android.os.RemoteException;
7+
8+
import com.android.internal.util.GoogleCameraUtils;
9+
import com.android.settings.R;
10+
import com.android.settings.ext.BoolSettingFragment;
11+
import com.android.settingslib.widget.FooterPreference;
12+
13+
public class GoogleSpecialAcceleratorAccessFragment extends BoolSettingFragment {
14+
private static final String TAG = GoogleSpecialAcceleratorAccessFragment.class.getSimpleName();
15+
16+
@Override
17+
protected BoolSetting getSetting() {
18+
return ExtSettings.ALLOW_GOOGLE_APPS_SPECIAL_ACCESS_TO_ACCELERATORS;
19+
}
20+
21+
@Override
22+
protected CharSequence getTitle() {
23+
return resText(R.string.Google_apps_special_accelerator_access_title);
24+
}
25+
26+
@Override
27+
protected CharSequence getMainSwitchTitle() {
28+
return resText(R.string.Google_apps_special_accelerator_access_main_switch);
29+
}
30+
31+
@Override
32+
protected void onMainSwitchChanged(boolean state) {
33+
if (GoogleCameraUtils.isCustomSeInfoNeededForAccessToAccelerators(requireContext())) {
34+
try {
35+
ActivityThread.getPackageManager().updateSeInfo(GoogleCameraUtils.PACKAGE_NAME);
36+
} catch (RemoteException e) {
37+
throw e.rethrowFromSystemServer();
38+
}
39+
}
40+
}
41+
42+
@Override
43+
protected FooterPreference makeFooterPref(FooterPreference.Builder builder) {
44+
return builder.setTitle(R.string.Google_apps_special_accelerator_access_footer).build();
45+
}
46+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.android.settings.applications.specialaccess;
2+
3+
import android.content.Context;
4+
import android.ext.settings.ExtSettings;
5+
6+
import com.android.settings.R;
7+
import com.android.settings.ext.BoolSettingFragmentPrefController;
8+
9+
public class GoogleSpecialAcceleratorAccessPrefController extends BoolSettingFragmentPrefController {
10+
11+
public GoogleSpecialAcceleratorAccessPrefController(Context ctx, String key) {
12+
super(ctx, key, ExtSettings.ALLOW_GOOGLE_APPS_SPECIAL_ACCESS_TO_ACCELERATORS);
13+
}
14+
15+
@Override
16+
public int getAvailabilityStatus() {
17+
if (!mContext.getResources().getBoolean(
18+
com.android.internal.R.bool.config_Google_apps_can_have_special_access_to_accelerators)) {
19+
return UNSUPPORTED_ON_DEVICE;
20+
}
21+
22+
return super.getAvailabilityStatus();
23+
}
24+
25+
@Override
26+
protected CharSequence getSummaryOn() {
27+
return resText(R.string.Google_apps_special_accelerator_access_summary_granted);
28+
}
29+
30+
@Override
31+
protected CharSequence getSummaryOff() {
32+
return resText(R.string.Google_apps_special_accelerator_access_summary_not_granted);
33+
}
34+
}

0 commit comments

Comments
 (0)