【干货】Android系统定制基础篇:第十四部分(禁止第三方应用调用系统设置、增加TP配置、增加摄像头镜像设置、增加摄像头默认角度设置、修改默认语言)

这篇具有很好参考价值的文章主要介绍了【干货】Android系统定制基础篇:第十四部分(禁止第三方应用调用系统设置、增加TP配置、增加摄像头镜像设置、增加摄像头默认角度设置、修改默认语言)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、Android禁止第三方应用调用系统设置

修改文件 frameworks\base\core\java\android\app\ActivityManagerNative.java 如下:

@Override
public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
    throws RemoteException {
    switch (code) {
        case START_ACTIVITY_TRANSACTION:
            {
                data.enforceInterface(IActivityManager.descriptor);
                IBinder b = data.readStrongBinder();
                IApplicationThread app = ApplicationThreadNative.asInterface(b);
                String callingPackage = data.readString();
                Intent intent = Intent.CREATOR.createFromParcel(data);

                // Add by shenhb@topband, for forbid third party APP calling system settings.
                String action = intent.getAction();
                if (null != action && action.contains("android.settings.")) {
                    if (!(null == callingPackage || callingPackage.contains("com.android") || callingPackage.contains("com.topband"))) {
                        if ("1".equals(SystemProperties.get("persist.sys.forbid_to_settings","0"))) {
                            Log.w("ActivityManagerNative", "Third party APP forbid calling system settings: " + callingPackage);
                            return true;
                        }
                    }
                }
                // Add end

                String resolvedType = data.readString();
                IBinder resultTo = data.readStrongBinder();

属性配置:

# 取值,0:关,1:开
persist.sys.forbid_to_settings=1

二、Android增加TP配置:xy交换,x反转,y反转

Android 主板定制过程中经常出现客户需要临时适配各种 TP(包括 USB TP),因此在设置菜单中加入 xy 交换,x 反转,y 反转常用配置,以客户多样性需求。
以下修改基于Android 8.1 SDK,如下:

diff --git a/frameworks/native/services/inputflinger/InputReader.cpp b/frameworks/native/services/inputflinger/InputReader.cpp
old mode 100644
new mode 100755
index 5e363c5..7207a83
--- a/frameworks/native/services/inputflinger/InputReader.cpp
+++ b/frameworks/native/services/inputflinger/InputReader.cpp
@@ -7062,6 +7062,23 @@ bool SingleTouchInputMapper::hasStylus() const {
 
 MultiTouchInputMapper::MultiTouchInputMapper(InputDevice* device) :
         TouchInputMapper(device) {
+    // Add by shenhb@topband.com.cn, for usb tp rotate
+    char *value = new char[PROPERTY_VALUE_MAX];
+    
+    memset(value,0,2);
+    property_get("persist.sys.touch.swap_xy", value, "0");
+    mSwapXY = (value[0] == '1' ? 1:0);
+    
+    memset(value,0,2);
+    property_get("persist.sys.touch.x_reverse", value, "0");
+    mXReverse = (value[0] == '1' ? 1:0);
+    
+    memset(value,0,2);
+    property_get("persist.sys.touch.y_reverse", value, "0");
+    mYReverse = (value[0] == '1' ? 1:0);
+    
+    ALOGI("MultiTouchInputMapper, mSwapXY=%d mXReverse=%d mYReverse=%d", mSwapXY, mXReverse, mYReverse);
+    // Add end
 }
 
 MultiTouchInputMapper::~MultiTouchInputMapper() {
@@ -7076,9 +7093,33 @@ void MultiTouchInputMapper::reset(nsecs_t when) {
 }
 
 void MultiTouchInputMapper::process(const RawEvent* rawEvent) {
-    TouchInputMapper::process(rawEvent);
+    // Add by shenhb@topband.com.cn, for usb tp rotate
+    RawEvent rawEvent1;
+    memcpy(&rawEvent1, rawEvent, sizeof(RawEvent));
+
+    if(mSwapXY) {
+        if(rawEvent1.code == ABS_MT_POSITION_X) {
+            rawEvent1.code = ABS_MT_POSITION_Y;
+        } else if(rawEvent1.code == ABS_MT_POSITION_Y) {
+            rawEvent1.code = ABS_MT_POSITION_X;
+        }
+    }
+    
+    if(mXReverse) {
+        if(rawEvent1.code == ABS_MT_POSITION_X) {
+            rawEvent1.value = mRawPointerAxes.x.maxValue - rawEvent1.value;
+        }
+    }
+    
+    if(mYReverse) {
+        if(rawEvent1.code == ABS_MT_POSITION_Y) {
+            rawEvent1.value = mRawPointerAxes.y.maxValue - rawEvent1.value;
+        }
+    }
+    // Add end
 
-    mMultiTouchMotionAccumulator.process(rawEvent);
+    TouchInputMapper::process(&rawEvent1);
+    mMultiTouchMotionAccumulator.process(&rawEvent1);
 }
 
 void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) {
@@ -7180,6 +7221,17 @@ void MultiTouchInputMapper::configureRawPointerAxes() {
     getAbsoluteAxisInfo(ABS_MT_DISTANCE, &mRawPointerAxes.distance);
     getAbsoluteAxisInfo(ABS_MT_TRACKING_ID, &mRawPointerAxes.trackingId);
     getAbsoluteAxisInfo(ABS_MT_SLOT, &mRawPointerAxes.slot);
+    
+    // Add by shenhb@topband.com.cn, for usb tp rotate
+    if(mSwapXY) {
+        RawAbsoluteAxisInfo tmp;		
+        memset(&tmp, 0, sizeof(RawAbsoluteAxisInfo));
+        memcpy(&tmp, &mRawPointerAxes.x, sizeof(RawAbsoluteAxisInfo));
+        memcpy(&mRawPointerAxes.x, &mRawPointerAxes.y, sizeof(RawAbsoluteAxisInfo));
+        memcpy(&mRawPointerAxes.y, &tmp, sizeof(RawAbsoluteAxisInfo));
+        ALOGI("mRawPointerAxes.x.maxValue=%d mRawPointerAxes.y.maxValue=%d", mRawPointerAxes.x.maxValue, mRawPointerAxes.y.maxValue);
+    }
+    // Add end
 
     if (mRawPointerAxes.trackingId.valid
             && mRawPointerAxes.slot.valid
diff --git a/frameworks/native/services/inputflinger/InputReader.h b/frameworks/native/services/inputflinger/InputReader.h
old mode 100644
new mode 100755
index e6dace1..3d5815e
--- a/frameworks/native/services/inputflinger/InputReader.h
+++ b/frameworks/native/services/inputflinger/InputReader.h
@@ -1942,6 +1942,9 @@ private:
     // Specifies the pointer id bits that are in use, and their associated tracking id.
     BitSet32 mPointerIdBits;
     int32_t mPointerTrackingIdMap[MAX_POINTER_ID + 1];
+    int mSwapXY;
+    int mXReverse;
+    int mYReverse;
 };
 
 class ExternalStylusInputMapper : public InputMapper {
diff --git a/packages/apps/Settings/res/values-zh-rCN/strings.xml b/packages/apps/Settings/res/values-zh-rCN/strings.xml
old mode 100644
new mode 100755
index 89605cc..6ddff82
--- a/packages/apps/Settings/res/values-zh-rCN/strings.xml
+++ b/packages/apps/Settings/res/values-zh-rCN/strings.xml
@@ -3736,4 +3736,10 @@
     <string name="later">秒以后截屏</string>
     <string name="abc_on" >"系统日志收集器"</string>
     <string name="abc_on_summary" >"收集的日志保存在/data/logs/目录下"</string>
+	
+	<!--Add by shenhb@topband.com.cn-->
+    <string name="touch_screen_swap_xy_title">"触摸屏XY方向切换"</string>
+    <string name="touch_screen_x_reverse_title">"触摸屏X方向反转"</string>
+    <string name="touch_screen_y_reverse_title">"触摸屏Y方向反转"</string>
+    <!--Add end-->
 </resources>
diff --git a/packages/apps/Settings/res/values/strings.xml b/packages/apps/Settings/res/values/strings.xml
index 848b941..822493e 100755
--- a/packages/apps/Settings/res/values/strings.xml
+++ b/packages/apps/Settings/res/values/strings.xml
@@ -9109,4 +9109,11 @@
     <string name="later">s later capture</string>
     <string name="abc_on" >"Android bug collector"</string>
     <string name="abc_on_summary" >"Log will be saved in /data/logs/"</string>
+	
+	<!--Add by shenhb@topband.com.cn-->
+    <string name="touch_screen_swap_xy_title">"Touch Screen swap x2y"</string>
+    <string name="touch_screen_x_reverse_title">"Touch Screen x reverse"</string>
+    <string name="touch_screen_y_reverse_title">"Touch Screen y reverse"</string>
+    <!--Add end-->
+
 </resources>
diff --git a/packages/apps/Settings/res/xml/display_settings.xml b/packages/apps/Settings/res/xml/display_settings.xml
old mode 100644
new mode 100755
index 87d3e5e..328871d
--- a/packages/apps/Settings/res/xml/display_settings.xml
+++ b/packages/apps/Settings/res/xml/display_settings.xml
@@ -85,6 +85,18 @@
         android:key="screensaver"
         android:title="@string/screensaver_settings_title"
         android:fragment="com.android.settings.dream.DreamSettings" />
+		
+	<SwitchPreference
+		android:key="touch_swap_xy"
+		android:title="@string/touch_screen_swap_xy_title" />
+		
+	<SwitchPreference
+		android:key="touch_x_reverse"
+		android:title="@string/touch_screen_x_reverse_title" />
+		
+	<SwitchPreference
+		android:key="touch_y_reverse"
+		android:title="@string/touch_screen_y_reverse_title" />
 
     <!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
     <Preference
diff --git a/packages/apps/Settings/src/com/android/settings/DisplaySettings.java b/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
old mode 100644
new mode 100755
index 86c3da1..ef0e19e
--- a/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
+++ b/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
@@ -33,6 +33,9 @@ import com.android.settings.display.LiftToWakePreferenceController;
 import com.android.settings.display.NightDisplayPreferenceController;
 import com.android.settings.display.NightModePreferenceController;
 import com.android.settings.display.ScreenSaverPreferenceController;
+import com.android.settings.display.TouchScreenSwapXYPreferenceController;
+import com.android.settings.display.TouchScreenXReversePreferenceController;
+import com.android.settings.display.TouchScreenYReversePreferenceController;
 import com.android.settings.display.TapToWakePreferenceController;
 import com.android.settings.display.ThemePreferenceController;
 import com.android.settings.display.TimeoutPreferenceController;
@@ -97,6 +100,9 @@ public class DisplaySettings extends DashboardFragment {
         controllers.add(new NightDisplayPreferenceController(context));
         controllers.add(new NightModePreferenceController(context));
         controllers.add(new ScreenSaverPreferenceController(context));
+        controllers.add(new TouchScreenSwapXYPreferenceController(context));
+        controllers.add(new TouchScreenXReversePreferenceController(context));
+        controllers.add(new TouchScreenYReversePreferenceController(context));
         controllers.add(new AmbientDisplayPreferenceController(
                 context,
                 new AmbientDisplayConfiguration(context),
diff --git a/packages/apps/Settings/src/com/android/settings/display/TouchScreenSwapXYPreferenceController.java b/packages/apps/Settings/src/com/android/settings/display/TouchScreenSwapXYPreferenceController.java
new file mode 100755
index 0000000..8ffec77
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/display/TouchScreenSwapXYPreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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.settings.display;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+import android.os.SystemProperties;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class TouchScreenSwapXYPreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin, Preference.OnPreferenceChangeListener{
+
+    private static final String KEY_TOUCH_SWAP_XY = "touch_swap_xy";
+    private TwoStatePreference mPreference;
+
+    public TouchScreenSwapXYPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_TOUCH_SWAP_XY;
+    }
+    
+    @Override
+    public void updateState(Preference preference) {
+        mPreference = (TwoStatePreference) preference;
+        updatePreference();
+    }
+    
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+    
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (boolean) newValue;
+		SystemProperties.set("persist.sys.touch.swap_xy", (value ? "1" : "0"));
+        return true;
+    }
+    
+    private void updatePreference() {
+        if (mPreference == null) {
+            return;
+        }
+        mPreference.setChecked(SystemProperties.get("persist.sys.touch.swap_xy").equals("1"));
+    }
+}
diff --git a/packages/apps/Settings/src/com/android/settings/display/TouchScreenXReversePreferenceController.java b/packages/apps/Settings/src/com/android/settings/display/TouchScreenXReversePreferenceController.java
new file mode 100755
index 0000000..457262d
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/display/TouchScreenXReversePreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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.settings.display;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+import android.os.SystemProperties;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class TouchScreenXReversePreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin, Preference.OnPreferenceChangeListener{
+
+    private static final String KEY_TOUCH_X_REVERSE = "touch_x_reverse";
+    private TwoStatePreference mPreference;
+
+    public TouchScreenXReversePreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_TOUCH_X_REVERSE;
+    }
+    
+    @Override
+    public void updateState(Preference preference) {
+        mPreference = (TwoStatePreference) preference;
+        updatePreference();
+    }
+    
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+    
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (boolean) newValue;
+		SystemProperties.set("persist.sys.touch.x_reverse", (value ? "1" : "0"));
+        return true;
+    }
+    
+    private void updatePreference() {
+        if (mPreference == null) {
+            return;
+        }
+        mPreference.setChecked(SystemProperties.get("persist.sys.touch.x_reverse").equals("1"));
+    }
+}
diff --git a/packages/apps/Settings/src/com/android/settings/display/TouchScreenYReversePreferenceController.java b/packages/apps/Settings/src/com/android/settings/display/TouchScreenYReversePreferenceController.java
new file mode 100755
index 0000000..ef2e5d7
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/display/TouchScreenYReversePreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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.settings.display;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+import android.os.SystemProperties;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class TouchScreenYReversePreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin, Preference.OnPreferenceChangeListener{
+
+    private static final String KEY_TOUCH_Y_REVERSE = "touch_y_reverse";
+    private TwoStatePreference mPreference;
+
+    public TouchScreenYReversePreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_TOUCH_Y_REVERSE;
+    }
+    
+    @Override
+    public void updateState(Preference preference) {
+        mPreference = (TwoStatePreference) preference;
+        updatePreference();
+    }
+    
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+    
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (boolean) newValue;
+		SystemProperties.set("persist.sys.touch.y_reverse", (value ? "1" : "0"));
+        return true;
+    }
+    
+    private void updatePreference() {
+        if (mPreference == null) {
+            return;
+        }
+        mPreference.setChecked(SystemProperties.get("persist.sys.touch.y_reverse").equals("1"));
+    }
+}

属性配置:

# xy交换,取值:0:关,1:开
persist.sys.touch.swap_xy=0

# x反转,取值:0:关,1:开
persist.sys.touch.x_reverse=0

# y反转,取值:0:关,1:开
persist.sys.touch.y_reverse=0

三、Android增加摄像头镜像设置

Android 主板定制时,常常使用 UVC 摄像头,无前后摄像头之分,有时客户需要将默认摄像头当做前摄像头使用,要求画面是镜像的。
以下修改基于Android 8.1 SDK,如下:

commit e12a62c6ccffc56cfc1f12e87ce82e8f116f2891
Author: shenhb <shenhb@topband.com.cn>
Date:   Fri Mar 15 10:06:20 2019 +0800Camera】设置菜单中增加摄像头镜像功能

diff --git a/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp b/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp
index 761458d..037b221 100755
--- a/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp
+++ b/frameworks/av/services/camera/libcameraservice/api1/CameraClient.cpp
@@ -735,7 +735,17 @@ status_t CameraClient::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) {
 
     if (cmd == CAMERA_CMD_SET_DISPLAY_ORIENTATION) {
         // Mirror the preview if the camera is front-facing.
-        orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
+        
+        // Add by shenhb@topband.com.cn, for force all cameras to mirror
+        char value[PROPERTY_VALUE_MAX];
+        property_get("persist.sys.camera_mirror", value, "0");
+        if (strcmp(value, "0") != 0) {
+            orientation = getOrientation(arg1, 1);
+        } else {
+            orientation = getOrientation(arg1, mCameraFacing == CAMERA_FACING_FRONT);
+        }
+        // Add end
+        
         if (orientation == -1) return BAD_VALUE;
 
         if (mOrientation != orientation) {
diff --git a/packages/apps/Settings/res/values-zh-rCN/strings.xml b/packages/apps/Settings/res/values-zh-rCN/strings.xml
index e44186b..3eef968 100755
--- a/packages/apps/Settings/res/values-zh-rCN/strings.xml
+++ b/packages/apps/Settings/res/values-zh-rCN/strings.xml
@@ -3747,5 +3747,6 @@
     <string name="sleep_setting_title">永不休眠</string>
     <string name="dropdown_setting_title">禁止状态栏下拉</string>
     <string name="app_rotation_setting_title">禁止应用旋转</string>
+    <string name="camera_mirror_setting_title">摄像头镜像</string>
     <!--Add end-->
 </resources>
diff --git a/packages/apps/Settings/res/values/strings.xml b/packages/apps/Settings/res/values/strings.xml
index 9ab6a57..4e0844e 100755
--- a/packages/apps/Settings/res/values/strings.xml
+++ b/packages/apps/Settings/res/values/strings.xml
@@ -9120,6 +9120,7 @@
     <string name="sleep_setting_title">Never sleep</string>
     <string name="dropdown_setting_title">Disable drop-down window</string>
     <string name="app_rotation_setting_title">Disable app rotation</string>
+    <string name="camera_mirror_setting_title">Camera mirror</string>
     <!--Add end-->
 
 </resources>
diff --git a/packages/apps/Settings/res/xml/display_settings.xml b/packages/apps/Settings/res/xml/display_settings.xml
index 64f29d1..4834e00 100755
--- a/packages/apps/Settings/res/xml/display_settings.xml
+++ b/packages/apps/Settings/res/xml/display_settings.xml
@@ -121,6 +121,10 @@
 	<SwitchPreference
 		android:key="never_sleep"
 		android:title="@string/sleep_setting_title" />
+
+	<SwitchPreference
+		android:key="camera_mirror"
+		android:title="@string/camera_mirror_setting_title" />
 	<!--Add end-->
 
     <!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
diff --git a/packages/apps/Settings/src/com/android/settings/DisplaySettings.java b/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
index 7a68023..ba0be59 100755
--- a/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
+++ b/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
@@ -41,6 +41,7 @@ import com.android.settings.display.NavbarPreferenceController;
 import com.android.settings.display.DropdownPreferenceController;
 import com.android.settings.display.AppRotationPreferenceController;
 import com.android.settings.display.SleepPreferenceController;
+import com.android.settings.display.CameraMirrorPreferenceController;
 import com.android.settings.display.TapToWakePreferenceController;
 import com.android.settings.display.ThemePreferenceController;
 import com.android.settings.display.TimeoutPreferenceController;
@@ -113,6 +114,7 @@ public class DisplaySettings extends DashboardFragment {
         controllers.add(new DropdownPreferenceController(context));
         controllers.add(new AppRotationPreferenceController(context));
         controllers.add(new SleepPreferenceController(context));
+        controllers.add(new CameraMirrorPreferenceController(context));
         controllers.add(new AmbientDisplayPreferenceController(
                 context,
                 new AmbientDisplayConfiguration(context),
diff --git a/packages/apps/Settings/src/com/android/settings/display/CameraMirrorPreferenceController.java b/packages/apps/Settings/src/com/android/settings/display/CameraMirrorPreferenceController.java
new file mode 100755
index 0000000..bc0b900
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/display/CameraMirrorPreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 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.settings.display;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.TwoStatePreference;
+import android.os.SystemProperties;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class CameraMirrorPreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin, Preference.OnPreferenceChangeListener{
+
+    private static final String KEY_CAMERA_MIRROR = "camera_mirror";
+    private TwoStatePreference mPreference;
+
+    public CameraMirrorPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_CAMERA_MIRROR;
+    }
+    
+    @Override
+    public void updateState(Preference preference) {
+        mPreference = (TwoStatePreference) preference;
+        updatePreference();
+    }
+    
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+    
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+        boolean value = (boolean) newValue;
+		SystemProperties.set("persist.sys.camera_mirror", (value ? "1" : "0"));
+        return true;
+    }
+    
+    private void updatePreference() {
+        if (mPreference == null) {
+            return;
+        }
+        mPreference.setChecked(SystemProperties.get("persist.sys.camera_mirror").equals("1"));
+    }
+}

属性配置:

# 取值:0:关,1:开
persist.sys.camera_mirror=0

四、Android增加摄像头默认角度设置

以下修改基于Android 8.1 SDK,如下:

commit b2ab76f0e0988112680cc580ed016bd5ef856e27
Author: shenhb <shenhb@topband.com.cn>
Date:   Thu Mar 28 17:06:07 2019 +0800Camera】支持在设置菜单中设置相机默认角度

diff --git a/hardware/rockchip/camera/CameraHal/CameraHal_Module.cpp b/hardware/rockchip/camera/CameraHal/CameraHal_Module.cpp
index bf2f997..84e3e45 100755
--- a/hardware/rockchip/camera/CameraHal/CameraHal_Module.cpp
+++ b/hardware/rockchip/camera/CameraHal/CameraHal_Module.cpp
@@ -1216,22 +1216,12 @@ int camera_get_number_of_cameras(void)
     }
 #endif
     
+    property_get("persist.sys.camera.rotation", property, "0");
+    hwrotation = strtol(property,0,0);
     for (int i = 0; i < gCamerasNumber; i++) {
         memcpy(&gCamInfos[i], &camInfoTmp[i], sizeof(rk_cam_info_t));
+        gCamInfos[i].facing_info.orientation = hwrotation; 
     }
-
-    property_get("persist.sys.sf.hwrotation", property, "0");
-    hwrotation = strtol(property,0,0);
-
-#if 0
-    if (hwrotation == 0) {
-        gCamInfos[0].facing_info.orientation = 0;    /* ddl@rock-chips.com: v0.4.17 */ 
-        gCamInfos[1].facing_info.orientation = 0;
-    }
-#endif
-//for test isp,zyc
-//  gCamerasNumber =1;
-//  gCamInfos[0].facing_info.orientation = 180;
     
 camera_get_number_of_cameras_end:
     LOGD("%s(%d): Current board have %d cameras attached.",__FUNCTION__, __LINE__, gCamerasNumber);
@@ -1374,19 +1364,12 @@ loop_continue:
     }
     #endif
     
-    memcpy(&gCamInfos[0], &camInfoTmp[0], sizeof(rk_cam_info_t));
-    memcpy(&gCamInfos[1], &camInfoTmp[1], sizeof(rk_cam_info_t));
-
-
-    property_get("persist.sys.sf.hwrotation", property, "0");
+    property_get("persist.sys.camera.rotation", property, "0");
     hwrotation = strtol(property,0,0);
-
-    if (hwrotation == 0) {
-        gCamInfos[0].facing_info.orientation = 0;    /* ddl@rock-chips.com: v0.4.17 */ 
-        gCamInfos[1].facing_info.orientation = 0;
+    for (int i = 0; i < gCamerasNumber; i++) {
+        memcpy(&gCamInfos[i], &camInfoTmp[i], sizeof(rk_cam_info_t));
+        gCamInfos[i].facing_info.orientation = hwrotation; 
     }
-//for test isp,zyc
-  gCamerasNumber =1;
     
 camera_get_number_of_cameras_end:
     LOGD("%s(%d): Current board have %d cameras attached.",__FUNCTION__, __LINE__, gCamerasNumber);
diff --git a/packages/apps/Settings/res/values-zh-rCN/strings.xml b/packages/apps/Settings/res/values-zh-rCN/strings.xml
index 3eef968..f7aa6b2 100755
--- a/packages/apps/Settings/res/values-zh-rCN/strings.xml
+++ b/packages/apps/Settings/res/values-zh-rCN/strings.xml
@@ -3748,5 +3748,6 @@
     <string name="dropdown_setting_title">禁止状态栏下拉</string>
     <string name="app_rotation_setting_title">禁止应用旋转</string>
     <string name="camera_mirror_setting_title">摄像头镜像</string>
+    <string name="camera_angle_setting_title">摄像头默认角度</string>
     <!--Add end-->
 </resources>
diff --git a/packages/apps/Settings/res/values/arrays.xml b/packages/apps/Settings/res/values/arrays.xml
index 519727b..1176c4f 100755
--- a/packages/apps/Settings/res/values/arrays.xml
+++ b/packages/apps/Settings/res/values/arrays.xml
@@ -53,6 +53,21 @@
         <item>180</item>
         <item>270</item>
     </string-array>
+	
+	<!--Camera settings. Set the camera default angle-->
+    <string-array name="camera_angle_entries">
+        <item>0</item>
+        <item>90</item>
+        <item>180</item>
+        <item>270</item>
+    </string-array>
+
+    <string-array name="camera_angle_values" translatable="false">
+        <item>0</item>
+        <item>90</item>
+        <item>180</item>
+        <item>270</item>
+    </string-array>
 
     <!-- Display settings.  The delay in inactivity before the screen is turned off. These are shown in a list dialog. -->
     <string-array name="screen_timeout_entries">
diff --git a/packages/apps/Settings/res/values/strings.xml b/packages/apps/Settings/res/values/strings.xml
index 4e0844e..e4cfd20 100755
--- a/packages/apps/Settings/res/values/strings.xml
+++ b/packages/apps/Settings/res/values/strings.xml
@@ -9121,6 +9121,7 @@
     <string name="dropdown_setting_title">Disable drop-down window</string>
     <string name="app_rotation_setting_title">Disable app rotation</string>
     <string name="camera_mirror_setting_title">Camera mirror</string>
+	<string name="camera_angle_setting_title">Camera default angle</string>
     <!--Add end-->
 
 </resources>
diff --git a/packages/apps/Settings/res/xml/display_settings.xml b/packages/apps/Settings/res/xml/display_settings.xml
index 4834e00..9964dd2 100755
--- a/packages/apps/Settings/res/xml/display_settings.xml
+++ b/packages/apps/Settings/res/xml/display_settings.xml
@@ -125,6 +125,12 @@
 	<SwitchPreference
 		android:key="camera_mirror"
 		android:title="@string/camera_mirror_setting_title" />
+		
+	<ListPreference
+		android:key="camera_angle"
+		android:title="@string/camera_angle_setting_title"
+		android:entries="@array/camera_angle_entries"
+		android:entryValues="@array/camera_angle_values" />
 	<!--Add end-->
 
     <!-- Cross-listed item, if you change this, also change it in power_usage_summary.xml -->
diff --git a/packages/apps/Settings/src/com/android/settings/DisplaySettings.java b/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
index ba0be59..6cbe2cc 100755
--- a/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
+++ b/packages/apps/Settings/src/com/android/settings/DisplaySettings.java
@@ -42,6 +42,7 @@ import com.android.settings.display.DropdownPreferenceController;
 import com.android.settings.display.AppRotationPreferenceController;
 import com.android.settings.display.SleepPreferenceController;
 import com.android.settings.display.CameraMirrorPreferenceController;
+import com.android.settings.display.CameraAnglePreferenceController;
 import com.android.settings.display.TapToWakePreferenceController;
 import com.android.settings.display.ThemePreferenceController;
 import com.android.settings.display.TimeoutPreferenceController;
@@ -115,6 +116,7 @@ public class DisplaySettings extends DashboardFragment {
         controllers.add(new AppRotationPreferenceController(context));
         controllers.add(new SleepPreferenceController(context));
         controllers.add(new CameraMirrorPreferenceController(context));
+        controllers.add(new CameraAnglePreferenceController(context));
         controllers.add(new AmbientDisplayPreferenceController(
                 context,
                 new AmbientDisplayConfiguration(context),
diff --git a/packages/apps/Settings/src/com/android/settings/display/CameraAnglePreferenceController.java b/packages/apps/Settings/src/com/android/settings/display/CameraAnglePreferenceController.java
new file mode 100755
index 0000000..4990518
--- /dev/null
+++ b/packages/apps/Settings/src/com/android/settings/display/CameraAnglePreferenceController.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 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.settings.display;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.ListPreference;
+import android.os.SystemProperties;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class CameraAnglePreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin, Preference.OnPreferenceChangeListener{
+
+    private ListPreference mPreference;
+
+    public CameraAnglePreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return "camera_angle";
+    }
+    
+    @Override
+    public void updateState(Preference preference) {
+        mPreference = (ListPreference) preference;
+        updatePreference();
+    }
+    
+    @Override
+    public boolean isAvailable() {
+        return true;
+    }
+    
+    @Override
+    public boolean onPreferenceChange(Preference preference, Object newValue) {
+		SystemProperties.set("persist.sys.camera.rotation", (String) newValue);
+        return true;
+    }
+    
+    private void updatePreference() {
+        if (mPreference == null) {
+            return;
+        }
+        mPreference.setValue(SystemProperties.get("persist.sys.camera.rotation", "0"));
+    }
+}

属性配置:

# 取值:0,90,180,270
persist.sys.camera.rotation=0

五、Android修改默认语言为中文

修改默认语言
修改文件 build/make/target/product/full_base.mk 如下:

PRODUCT_LOCALES := zh_CN

删除多余的语言包
修改文件 build/make/target/product/locales_full.mk 删除多余的包:文章来源地址https://www.toymoban.com/news/detail-495417.html

PRODUCT_LOCALES := en_US zh_HK zh_CN

到了这里,关于【干货】Android系统定制基础篇:第十四部分(禁止第三方应用调用系统设置、增加TP配置、增加摄像头镜像设置、增加摄像头默认角度设置、修改默认语言)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【干货】Android系统定制基础篇:第三部分(Android静默安装、Android支持usb打印机)

    一些产品要求APP在升级时能够实现静默安装,而无需弹出安装界面让用户确认。这里提出两种实现方案: 方案一 APP调用『pm』命令实现静默安装,此方案无须修改Android源码,但需要root权限。 方案二 修改Android PackageInstaller 源码,增加Intent参数来指定是否要静默安装,同时支

    2024年02月10日
    浏览(47)
  • 【干货】Android系统定制基础篇:第二部分(Launcher3支持键盘切换焦点、开发者模式密码确认、禁止非预装应用安装、配置时间)

    Android Launcher3 默认并不支持键盘操作,无法切换焦点,在一些需要支持键盘或遥控操作的设备中无法使用,因些对 Launcher3 做简单修改,使其支持键盘切换焦点。 在安全性要求比较高的产品中,一般会默认关闭『adb调试』,同时禁止用户打开『adb调试』功能。在Android8.1中默认

    2024年02月10日
    浏览(52)
  • 【干货】Android系统定制基础篇:第一部分(文件权限、增加信号强度、双路背光控制)

    当需要修改某文件或路径权限时,我们可以在init.rc开机启动某节点添加chmod命令进行修改。但是对于system分区,由于是ro权限,在init.rc使用chmod修改权限无效。需要在文件编译时,对权限进行修改。不同的Android版本改法一样,但是文件所在目录有差异,Android O主要修改文件是

    2024年02月09日
    浏览(50)
  • 第十四届蓝桥杯编程题部分代码题解

    C. 冶炼金属 最大值就是取 a / b a / b a / b 的最小值,最小值就是二分找到满足 m i d ∗ ( b i + 1 ) ≥ a i mid * (b_i + 1) ≥ a_i mi d ∗ ( b i ​ + 1 ) ≥ a i ​ 的最小值 D. 飞机降落 全排列枚举所有降落方案,然后判断即可 E. 接龙数列 状态定义: f [ i , j ] f[i, j] f [ i , j ] 为前 i i i 个数,

    2023年04月11日
    浏览(42)
  • Android 13 Hotseat定制化修改——005 hotseat图标禁止形成文件夹

    目录 一.背景 二.方案 由于需求是需要自定义修改Hotseat,所以此篇文章是记录如何自定义修改hotseat的,应该可以覆盖大部分场景,修改点有修改hotseat布局方向,hotseat图标数量,hotseat图标大小,hotseat布局位置,hotseat图标禁止形成文件夹,hotseat图标禁止移动到Launcher中,本篇

    2024年02月13日
    浏览(52)
  • Android 第十四章 FragmentContainerView

    FragmentContainerView extends FrameLayout FragmentContainerView是专门为Fragments设计的自定义布局。它扩展了FrameLayout,因此它可以可靠地处理Fragment 事务,并且它还具有与Fragment 行为协调的附加特性 FragmentContainerView应用作Fragments的容器,通常设置在活动的xml布局 FragmentContainerView将只允许

    2024年02月11日
    浏览(41)
  • Java基础---第十四篇

    平时可能大家使用的最多的就是使用 String 作为 HashMap 的 key,但是现在我们想使用某个自定 义类作为 HashMap 的 key,那就需要注意以下几点: 如果类重写了 equals 方法,它也应该重写 hashCode 方法。 类的所有实例需要遵循与 equals 和 hashCode 相关的规则。 如果一个类没有使用

    2024年02月07日
    浏览(45)
  • 【小黑嵌入式系统第十四课】μC/OS-III程序设计基础(三)——信号量(任务同步&资源同步)、事件标记组(与&或&多个任务)

    上一课: 【小黑嵌入式系统第十三课】PSoC 5LP第二个实验——中断控制实验 前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站:人工智能 1.1 简介 在实时多任务系统中, 信号量 (semaphore)被广泛用于:任务间对共享

    2024年02月02日
    浏览(65)
  • 第十四章 ObjectScript - 系统函数

    本节重点介绍 ObjectScript 中一些最常用的系统函数。 这些函数的名称不区分大小写。 类库还提供了大量实用方法,可以像使用函数一样使用它们。 在给定一些输入的情况下,可以使用以下函数来选择一个值: $CASE 将给定的测试表达式与一组比较值进行比较,然后返回与匹配

    2024年02月10日
    浏览(35)
  • 【STM32】基础知识 第十四课 串口通信: 深入探究与应用

    在嵌入式系统中, 串口通信是一种常见的通信方式, 特别是在单片机领域. STM32 系列单片机提供了强大的串口 (UART) 功能, 可支持多种通信模式. 今天小白将带领大家深入探讨 STM32 的串口通信, 包括其基本原理, 配置方法, 中断处理及实际应用示例. 串口通信 (Serial Communication) 是一

    2024年02月15日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包