commit d210913d0bfe3d0160ba50b912379e5a85d3c86b Author: Anay Wadhera Date: Fri Dec 23 01:45:03 2022 +0900 SystemUIFlagFlipper: initial draft diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..acf2670 --- /dev/null +++ b/Android.bp @@ -0,0 +1,25 @@ +// Copyright (C) 2022 StatiXOS +// +// 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. + +android_app { + name: "SystemUIFlagFlipper", + srcs: ["src/**/*.java"], + static_libs: ["SystemUIFlagsLib"], + resource_dirs: ["res"], + platform_apis: true, + system_ext_specific: true, + certificate: "platform", + privileged: true, + manifest: "AndroidManifest.xml", +} diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..668209c --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/values/config.xml b/res/values/config.xml new file mode 100644 index 0000000..9abe268 --- /dev/null +++ b/res/values/config.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..97b1efe --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,19 @@ + + + + Simple Device Configuration + diff --git a/src/com/statix/systemuiflags/BootReceiver.java b/src/com/statix/systemuiflags/BootReceiver.java new file mode 100644 index 0000000..9b3bd78 --- /dev/null +++ b/src/com/statix/systemuiflags/BootReceiver.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 StatiXOS + * + * 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.statix.systemuiflags; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; + +import com.android.systemui.flags.FlagManager; + +public class BootReceiver extends BroadcastReceiver { + private static final String TAG = "SystemUIFlagFlipper"; + + @Override + public void onReceive(Context context, Intent intent) { + FlagManager manager = new FlagManager(context, new Handler(Looper.getMainLooper())); + new Thread(() -> { + Log.i(TAG, "Updating SystemUIFlags at boot"); + updateFlags(context, manager); + }).start(); + } + + private void updateFlags(Context context, FlagManager flagManager) { + updateConfig(context, R.array.flags, flagManager); + } + + private void updateConfig(Context context, int configArray, FlagManager flagManager) { + // Set current properties + String[] rawProperties = context.getResources().getStringArray(configArray); + for (String property : rawProperties) { + // Format: namespace/key=value + String[] kv = property.split("="); + int id = Integer.parseInt(kv[0]); + boolean enabled = Boolean.parseBoolean(kv[1]); + Log.i(TAG, "Setting flag " + id + " to " + enabled); + + flagManager.setFlagValue(id, enabled); + } + } +}