当前位置:   article > 正文

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

android禁止第三方应用调用系统设置

一、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();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

属性配置:

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

二、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"));
+    }
+}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391

属性配置:

# 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

三、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"));
+    }
+}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156

属性配置:

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

四、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"));
+    }
+}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213

属性配置:

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

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

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

PRODUCT_LOCALES := zh_CN
  • 1

删除多余的语言包
修改文件 build/make/target/product/locales_full.mk 删除多余的包:

PRODUCT_LOCALES := en_US zh_HK zh_CN
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/461449
推荐阅读
相关标签
  

闽ICP备14008679号