TF卡控制接口

 实现接口的其他文件我就不一一赘述了,直接上重点

1,在frameworks/base/core/java/android/app/customized/ICustomizedService.aidl定义接口

package android.app.customized;
 
interface ICustomizedService{
    void allowTFcard(boolean iscontrol);
    boolean isTFcardAllowed();
}

 2,在frameworks/base/core/java/android/app/customized/CustomizedManager.java中定义

package android.app.customized;
 
import android.util.Log;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.RemoteException;
import android.provider.Settings;
import java.io.IOException;
import android.os.ServiceManager;
import android.os.IBinder;
import java.util.List;
import android.app.ActivityManager;
import android.graphics.Bitmap;
 
 
public class CustomizedManager{
    private static final String TAG="CustomizedManager";
    private static final boolean DBG=true;
    
    private static ICustomizedService mService;
    private final Context mContext;
 
 
    public CustomizedManager(Context context){
        mContext = context;
        mService = ICustomizedService.Stub.asInterface(
                ServiceManager.getService("customized"));
    }
    private static ICustomizedService getService(){
        if (mService != null) {
            return mService;
        }        
        IBinder b = ServiceManager.getService("customized");
        mService = ICustomizedService.Stub.asInterface(b);

        return mService;
    }
 
    public void allowTFcard(boolean iscontrol){
	    ICustomizedService service = getService();
        try {
            service.allowTFcard(iscontrol);
        } catch (RemoteException e) {}
    } 

    public boolean isTFcardAllowed(){
        ICustomizedService service = getService();
        try {
            return service.isTFcardAllowed();
        } catch (RemoteException e) {}
        return false;
    }
 
}

3, 在frameworks/base/services/core/java/com/android/server/customized/CustomizedService.java中实现allowTFcard和isTFcardAllowed接口

   /**
     *  28 add interface allowTFcard(boolean allow){}
     */
    public void allowTFcard(boolean iscontrol){
	long jh = Binder.clearCallingIdentity();
        StorageManager mStorageManager = StorageManager.from(mContext);
        final List<VolumeInfo> vols = mStorageManager.getVolumes();
        VolumeInfo sdcardVolume = null ;

        for(VolumeInfo vol : vols){
            if(vol.getDisk() != null && vol.getDisk().isSd()) sdcardVolume = vol;

            //如果需要获取usbotg的路径,则改为
            // if(vol.getDisk() != null &&vol.getDisk().isUsb()) usbotgVolume = vol;
        }
        if(sdcardVolume!= null) {
            String sdcardPath = sdcardVolume.getPath()==null ? null :sdcardVolume.getPath().toString();
            String sdcardState = sdcardVolume.getEnvironmentForState(sdcardVolume.getState());
            //外置SD卡已挂载,且路径有效
            // sdcardPath 外置SD卡的路径

            System.out.println("T iscontrol=="+iscontrol);
            System.out.println("T sdcardPath=="+sdcardPath);
            System.out.println("T sdcardState=="+sdcardState);

            System.out.println("sdcardVolume  not  null");
	    Settings.System.putInt(mContext.getContentResolver(), "isForbidTFcard",iscontrol ? 1 : 0);
            if(iscontrol){
		System.out.println("mount.......................");
                if(sdcardState.equals(Environment.MEDIA_UNMOUNTED) && sdcardPath != null){
                    mStorageManager.mount(sdcardVolume.getId());
                }
            }else{
		System.out.println("unmount.......................");
                if(sdcardState.equals(Environment.MEDIA_MOUNTED) && sdcardPath != null){
                    mStorageManager.unmount(sdcardVolume.getId());
                }
            }


        }else{
                System.out.println("sdcardVolume ==null");
        }
        Binder.restoreCallingIdentity(jh);
    }

    /**
     *  29 add interface isTFcardAllowed(){}
     */
    public boolean isTFcardAllowed(){
	if(Settings.System.getInt(mContext.getContentResolver(),"isForbidTFcard",0)==1) {
                return true;
        } else {
                return false;
        }

    }


  

还需要在frameworks/base/packages/SystemUI/src/com/android/systemui/usb/StorageNotification.java中修改部分功能

   public UnmountTask(Context context, VolumeInfo volume) {
            mStorageManager = context.getSystemService(StorageManager.class);
            mVolumeId = volume.getId();
        }

        @Override
        protected Exception doInBackground(Void... params) {
            try {
                mStorageManager.unmount(mVolumeId);
                return null;
            } catch (Exception e) {
                return e;
            }
        }
    }

    private Notification onVolumeMounted(VolumeInfo vol) {   //在onVolumeMounted中对sdcard开机是否加载进行判断
        if(vol.getDisk() != null && vol.getDisk().isSd()){
            System.out.println("isSd==================");
            String sdcardPath = vol.getPath()==null ? null :vol.getPath().toString();
            String sdcardState = vol.getEnvironmentForState(vol.getState());
            if(sdcardState.equals(Environment.MEDIA_MOUNTED) && sdcardPath != null){
                if(0 == Settings.System.getInt(mContext.getContentResolver(), "isForbidTFcard",0)){
                    System.out.println("onVolumeMounted unmount...........................");
                    new UnmountTask(mContext, vol).execute();
                    return null;
                }
            }
        }

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STM32系列微控制器通常具有SPI接口,可用于连接TF(也称为microSD)。以下是一种常见的连接方案: 1. 首先,确保你的STM32微控制器具有SPI接口。大多数STM32微控制器都具有多个SPI接口,你可以在相关的数据手册或参考手册中查找有关SPI接口的详细信息。 2. 确认你的TF是否支持SPI模式。在TF的规格书或数据手册中查找有关SPI模式的信息。大多数TF都支持SPI模式。 3. 连接TF与STM32微控制器的SPI接口。根据你使用的STM32型号和引脚分配,连接TF的以下引脚: - TFSDI(Serial Data In)引脚连接到STM32的SPI主设备的MISO(Master In Slave Out)引脚。 - TFSDO(Serial Data Out)引脚连接到STM32的SPI主设备的MOSI(Master Out Slave In)引脚。 - TF的SCK(Serial Clock)引脚连接到STM32的SPI主设备的SCK(Serial Clock)引脚。 - TF的CS(Chip Select)引脚连接到STM32的GPIO引脚。你可以选择任何一个GPIO引脚作为片选引脚。 4. 配置STM32的SPI接口。使用STM32的开发环境(如CubeMX或STM32CubeIDE),配置SPI接口的参数,例如时钟频率、数据位宽等。确保SPI接口的主从模式和时钟极性/相位设置与TF的要求相匹配。 5. 在你的代码中使用SPI接口TF进行通信。使用SPI驱动库或编写自己的SPI通信函数来实现与TF的读写操作。你可以使用SPI的读写寄存器或使用SPI库函数进行数据传输。 请注意,以上步骤只是一种常见的TF与STM32微控制器之间的连接方案。具体的实现可能因STM32型号、开发环境和TF的要求而有所不同。在实际应用中,你可能还需要处理TF的文件系统和数据读写等问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值