Add Settings UI for MTP transcoding over USB.
Enabling "Transcode exported media" means that the media transferred
from the device via MTP over USB would be transcoded, if necessary. This
switch also sets / unsets the sys.fuse.transcode_mtp system property.
"Transcode exported media" category would be accessible only when the
"File transfer / Audio Auto" or "PTP" radio button has been selected. We
are including PTP also since PTP supports transfer of videos.
Adding UsbDetailsTranscodeMtpController in a separate preference
category than "Charge connected device" primarily because they seemed to
be different in their own rights.
Here are a few screenshots:
https://screenshot.googleplex.com/8jeMstnSFsTtVCS.png
https://screenshot.googleplex.com/76hNz4iXp5dcX4M.png
https://screenshot.googleplex.com/AkTngE5hDDJCovv.png
https://screenshot.googleplex.com/4uQYGXuuSQLoz3w.png
BUG: 158466651
Test: manual testing. Also added unit test.
Change-Id: I2603a9bffed3320c193cc08f867bd67d9848da18
(cherry picked from commit 974662936e)
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 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.connecteddevice.usb;
|
||||
|
||||
import static android.hardware.usb.UsbPortStatus.DATA_ROLE_DEVICE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
/**
|
||||
* This class controls the switch for setting if we should transcode files transferred via MTP over
|
||||
* USB.
|
||||
*/
|
||||
public class UsbDetailsTranscodeMtpController extends UsbDetailsController
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
private static final String TRANSCODE_MTP_SYS_PROP_KEY = "sys.fuse.transcode_mtp";
|
||||
private static final String PREFERENCE_KEY = "usb_transcode_mtp";
|
||||
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private SwitchPreference mSwitchPreference;
|
||||
|
||||
public UsbDetailsTranscodeMtpController(Context context, UsbDetailsFragment fragment,
|
||||
UsbBackend backend) {
|
||||
super(context, fragment, backend);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreferenceCategory = screen.findPreference(getPreferenceKey());
|
||||
mSwitchPreference = new SwitchPreference(mPreferenceCategory.getContext());
|
||||
mSwitchPreference.setTitle(R.string.usb_transcode_files);
|
||||
mSwitchPreference.setOnPreferenceClickListener(this);
|
||||
mPreferenceCategory.addPreference(mSwitchPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh(boolean connected, long functions, int powerRole, int dataRole) {
|
||||
if (mUsbBackend.areFunctionsSupported(UsbManager.FUNCTION_MTP | UsbManager.FUNCTION_PTP)) {
|
||||
mFragment.getPreferenceScreen().addPreference(mPreferenceCategory);
|
||||
} else {
|
||||
mFragment.getPreferenceScreen().removePreference(mPreferenceCategory);
|
||||
}
|
||||
|
||||
mSwitchPreference.setChecked(SystemProperties.getBoolean(TRANSCODE_MTP_SYS_PROP_KEY, true));
|
||||
mPreferenceCategory.setEnabled(
|
||||
connected && isDeviceInFileTransferMode(functions, dataRole));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
SystemProperties.set(TRANSCODE_MTP_SYS_PROP_KEY,
|
||||
Boolean.toString(mSwitchPreference.isChecked()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return !Utils.isMonkeyRunning();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return PREFERENCE_KEY;
|
||||
}
|
||||
|
||||
private static boolean isDeviceInFileTransferMode(long functions, int dataRole) {
|
||||
return dataRole == DATA_ROLE_DEVICE && ((functions & UsbManager.FUNCTION_MTP) != 0
|
||||
|| (functions & UsbManager.FUNCTION_PTP) != 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user