删除多余的文件
This commit is contained in:
parent
25e36145aa
commit
2b56932e17
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/otg"
|
||||
settings:keywords="@string/otg">
|
||||
|
||||
<ListPreference
|
||||
android:title="@string/otg"
|
||||
android:entries="@array/usb_function_location"
|
||||
android:entryValues="@array/usb_function_location_values"
|
||||
android:key="usb_mode"
|
||||
android:persistent="true"/>
|
||||
</PreferenceScreen>
|
|
@ -1,163 +0,0 @@
|
|||
package com.android.settings;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UsbHostDeviceSetting extends SettingsPreferenceFragment implements OnPreferenceChangeListener {
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
private static final String KEY_USB_MODE_LOCATION = "usb_mode";
|
||||
private static final String RK3399_OTG_CTRL_PATH = "/sys/kernel/debug/usb/fe800000.usb/mode";
|
||||
private static final String RK3566_OTG_CTRL_PATH = "/sys/devices/platform/fe8a0000.usb2-phy/otg_mode";
|
||||
private static final String RK3568_OTG_CTRL_PATH = "/sys/devices/platform/fe8a0000.usb2-phy/otg_mode";
|
||||
private static final String RK3588_OTG_CTRL_PATH = "/sys/kernel/debug/usb/fc000000.usb/mode";
|
||||
|
||||
private static final String MODEL_PATH = "/proc/device-tree/compatible";
|
||||
|
||||
private static final String TAG = "UsbHostDeviceDebug";
|
||||
|
||||
private ListPreference mUsbMode;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.usb_host_device);
|
||||
|
||||
mContext = getActivity();
|
||||
|
||||
mUsbMode = (ListPreference) findPreference(KEY_USB_MODE_LOCATION);
|
||||
mUsbMode.setOnPreferenceChangeListener(this);
|
||||
|
||||
String currentMode = readFileValue(getCtrlPath());
|
||||
updateSummary(currentMode);
|
||||
}
|
||||
|
||||
private String getCtrlPath() {
|
||||
String platform = readFileValue(MODEL_PATH);
|
||||
String ctrlPath;
|
||||
|
||||
if ("".equals(platform)) return "";
|
||||
|
||||
if (platform.contains("3399")) {
|
||||
ctrlPath = RK3399_OTG_CTRL_PATH;
|
||||
} else if (platform.contains("3588")) {
|
||||
ctrlPath = RK3588_OTG_CTRL_PATH;
|
||||
} else if (platform.contains("3566") || platform.contains("3568") || platform.contains("356x")) {
|
||||
ctrlPath = RK3566_OTG_CTRL_PATH;
|
||||
} else {
|
||||
//do nothing
|
||||
Log.e(TAG, platform + ": otg mode switch not adaptation! should not be happened!!");
|
||||
ctrlPath = "";
|
||||
}
|
||||
return ctrlPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
// TODO Auto-generated method stub
|
||||
if (preference == mUsbMode) {
|
||||
|
||||
String platform = readFileValue(MODEL_PATH);
|
||||
String ctrlPath, modeString;
|
||||
String mode = (String) newValue;
|
||||
|
||||
if ("".equals(platform)) return true;
|
||||
|
||||
if (platform.contains("3399")) {
|
||||
ctrlPath = RK3399_OTG_CTRL_PATH;
|
||||
modeString = mode;
|
||||
} else if (platform.contains("3588")) {
|
||||
ctrlPath = RK3588_OTG_CTRL_PATH;
|
||||
modeString = mode;
|
||||
} else if (platform.contains("3566") || platform.contains("3568") || platform.contains("356x")) {
|
||||
ctrlPath = RK3566_OTG_CTRL_PATH;
|
||||
modeString = mode.equals("device") ? "otg" : "host";
|
||||
} else {
|
||||
//do nothing
|
||||
Log.e(TAG, platform + ": otg mode switch not adaptation! should not be happened!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.d(TAG, "usb mode is " + mode);
|
||||
writeFileWithValue(ctrlPath, modeString.getBytes());
|
||||
|
||||
//delay update summary
|
||||
Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String currentMode = readFileValue(ctrlPath);
|
||||
if(currentMode.equals(modeString))
|
||||
Toast.makeText(mContext, "otg mode switch success!", Toast.LENGTH_SHORT).show();
|
||||
else
|
||||
Toast.makeText(mContext, "otg mode switch failed!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
updateSummary(currentMode);
|
||||
}
|
||||
}, 1000); // 延时的毫秒数
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateSummary(String mode) {
|
||||
if (mode.equals("device") || mode.equals("otg")) {
|
||||
mUsbMode.setSummary("device mode");
|
||||
} else if (mode.equals("host")){
|
||||
mUsbMode.setSummary("host mode");
|
||||
} else {
|
||||
mUsbMode.setSummary("unknow mode");
|
||||
}
|
||||
}
|
||||
|
||||
private void writeFileWithValue(String path, byte[] buffer) {
|
||||
try {
|
||||
File file = new File(path);
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(buffer);
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String readFileValue(String path) {
|
||||
FileReader fileReader;
|
||||
String line;
|
||||
try {
|
||||
fileReader = new FileReader(path);
|
||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||
line = bufferedReader.readLine();
|
||||
bufferedReader.close();
|
||||
return line;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
// TODO Auto-generated method stub
|
||||
return 5;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue