修改文件 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(包括 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 [email protected], 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 [email protected], 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 [email protected], 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 主板定制时,常常使用 UVC 摄像头,无前后摄像头之分,有时客户需要将默认摄像头当做前摄像头使用,要求画面是镜像的。
以下修改基于Android 8.1 SDK,如下:
commit e12a62c6ccffc56cfc1f12e87ce82e8f116f2891
Author: shenhb <shenhb@topband.com.cn>
Date: Fri Mar 15 10:06:20 2019 +0800
【Camera】设置菜单中增加摄像头镜像功能
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 [email protected], 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 8.1 SDK,如下:
commit b2ab76f0e0988112680cc580ed016bd5ef856e27
Author: shenhb <shenhb@topband.com.cn>
Date: Thu Mar 28 17:06:07 2019 +0800
【Camera】支持在设置菜单中设置相机默认角度
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; /* [email protected]: 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; /* [email protected]: 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
修改默认语言
修改文件 build/make/target/product/full_base.mk 如下:
PRODUCT_LOCALES := zh_CN
删除多余的语言包
修改文件 build/make/target/product/locales_full.mk 删除多余的包:
PRODUCT_LOCALES := en_US zh_HK zh_CN