MTKSetings新增高精度定位菜单

 菜单开关只有在切换的时候生效,如果默认打开,需底层驱动直接将节点打开。

vendor/mediatek/proprietary/packages/apps/MtkSettings/res/xml/location_services.xml






        

        

        

        
        


vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/location/HighPercisionPreferenceController.java [新增类]

/*
 * Copyright 2021 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.location;

import android.content.Context;
import android.provider.Settings;

import androidx.preference.Preference;
import androidx.preference.SwitchPreference;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;

import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * Preference controller for Bluetooth scanning in Location Services.
 */
public class HighPercisionPreferenceController extends AbstractPreferenceController implements
        PreferenceControllerMixin, Preference.OnPreferenceChangeListener {

    private static final String KEY_HIGH_PERCISION = "custom_location_high_precision";

    public HighPercisionPreferenceController(Context context) {
        super(context);
    }

    @Override
    public boolean isAvailable() {
        return true;
    }

    @Override
    public String getPreferenceKey() {
        return KEY_HIGH_PERCISION;
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        boolean value = (Boolean) newValue;
	((SwitchPreference) preference).setChecked(value);
        if (value) {
            writeFile("/sys/devices/platform/droi_gpio_common/rfid_3v3_en","1");
            writeFile("/sys/devices/platform/droi_gpio_common/droi_rfid_power","1");
        } else {
            writeFile("/sys/devices/platform/droi_gpio_common/rfid_3v3_en","0");
            writeFile("/sys/devices/platform/droi_gpio_common/droi_rfid_power","0");
        }
        Settings.Secure.putInt(
                mContext.getContentResolver(), "tyd_location_high", value ? 1 : 0);
        return true;
    }

    @Override
    public void updateState(Preference preference) {
	Log.d("GTAG","updateState readFile() = "+readFile());
	int value = Settings.Secure.getInt(
                mContext.getContentResolver(), "tyd_location_high", 0);
        ((SwitchPreference) preference).setChecked(value != 0);
    }

    private void writeFile(String filePath, String line){
	Log.d("GTAG","writeFile line = "+line);
        File a = new File(filePath);
        try {
            FileOutputStream fs = new FileOutputStream(a);
            DataOutputStream ds = new DataOutputStream(fs);
            ds.write(line.getBytes());
            ds.flush();
            ds.close();
            fs.close();
        }
        catch (Exception ex) {
            Log.e("GTAG", "writeFile() Exception: " + ex);
        }
    }

    public static String readFile(){
        StringBuilder sb = new StringBuilder("");
        try {
            File file = new File("/sys/devices/platform/droi_gpio_common/rfid_3v3_en");
            FileInputStream inputStream = new FileInputStream(file);
            byte[] buffer = new byte[1024];
            int len = inputStream.read(buffer);
            while (len > 0) {
                sb.append(new String(buffer, 0, len));
                len = inputStream.read(buffer);
            }
            inputStream.close();
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return sb.toString();
    }
}

 vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/location/LocationServices.java

/*
 * Copyright (C) 2015 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.location;

import android.app.settings.SettingsEnums;
import android.content.Context;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.SearchIndexable;

import com.android.settings.location.HighPercisionPreferenceController;

import java.util.ArrayList;
import java.util.List;

/**
 * A page that configures the Location Services settings including Wi-Fi scanning, Bluetooth
 * scanning, and injected location services.
 */
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class LocationServices extends DashboardFragment {
    private static final String TAG = "LocationServicesSettings";

    @Override
    public int getMetricsCategory() {
        return SettingsEnums.LOCATION_SERVICES;
    }

    @Override
    protected int getPreferenceScreenResId() {
        return R.xml.location_services;
    }

    @Override
    protected String getLogTag() {
        return TAG;
    }

    @Override
    protected List createPreferenceControllers(Context context) {
        return buildPreferenceControllers(context);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        use(LocationInjectedServicesPreferenceController.class).init(this);
    }

    private static List buildPreferenceControllers(Context context) {
        final List controllers = new ArrayList<>();
        controllers.add(new WifiScanningPreferenceController(context));
        controllers.add(new BluetoothScanningPreferenceController(context));
//*/start
        controllers.add(new HighPercisionPreferenceController(context));
//*/end
        return controllers;
    }

    /**
     * For Search.
     */
    public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
            new BaseSearchIndexProvider(R.xml.location_services) {

                @Override
                public List createPreferenceControllers(Context
                        context) {
                    return buildPreferenceControllers(context);
                }
            };
}

overlay/vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values-zh-rCN/strings.xml

高精度定位
    使用高精度定位模块

overlay/vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values/strings.xml

  
   

High precision positioning
    USing High precision positioning module 

其余集成文件第三方提供!

你可能感兴趣的:(android,java)