Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03a545e5 authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge changes I00d6980a,I814221b4,Id88603a5

* changes:
  CameraBrowser: Launch itself when a camera is attached to USB.
  Send Intents when PTP compatible devices are connected/disconnected to USB
  Give system server permission to access USB.
parents 04839151 725552a0
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -55,6 +55,24 @@ public class Usb {
    public static final String ACTION_USB_STATE =
            "android.hardware.action.USB_STATE";

   /**
     * Broadcast Action:  A broadcast for USB camera attached event.
     *
     * This intent is sent when a USB device supporting PTP is attached to the host USB bus.
     * The intent's data contains a Uri for the device in the MTP provider.
     */
    public static final String ACTION_USB_CAMERA_ATTACHED =
            "android.hardware.action.USB_CAMERA_ATTACHED";

   /**
     * Broadcast Action:  A broadcast for USB camera detached event.
     *
     * This intent is sent when a USB device supporting PTP is detached from the host USB bus.
     * The intent's data contains a Uri for the device in the MTP provider.
     */
    public static final String ACTION_USB_CAMERA_DETACHED =
            "android.hardware.action.USB_CAMERA_DETACHED";

    /**
     * Boolean extra indicating whether USB is connected or disconnected.
     * Used in extras for the {@link #ACTION_USB_STATE} broadcast.
+1 −1
Original line number Diff line number Diff line
@@ -523,7 +523,7 @@ public class ZygoteInit {
        String args[] = {
            "--setuid=1000",
            "--setgid=1000",
            "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,3001,3002,3003",
            "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,3001,3002,3003",
            "--capabilities=130104352,130104352",
            "--runtime-init",
            "--nice-name=system_server",
+2 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@
    <protected-broadcast android:name="android.hardware.action.USB_CONNECTED" />
    <protected-broadcast android:name="android.hardware.action.USB_DISCONNECTED" />
    <protected-broadcast android:name="android.hardware.action.USB_STATE" />
    <protected-broadcast android:name="android.hardware.action.USB_CAMERA_ATTACHED" />
    <protected-broadcast android:name="android.hardware.action.USB_CAMERA_DETACHED" />

    <!-- ====================================== -->
    <!-- Permissions for things that cost money -->
+8 −0
Original line number Diff line number Diff line
@@ -14,6 +14,14 @@
        <activity android:name="StorageBrowser" />
        <activity android:name="ObjectBrowser" />
        <activity android:name="ObjectViewer" />

        <receiver android:name="UsbReceiver">
            <intent-filter>
                <action android:name="android.hardware.action.USB_CAMERA_ATTACHED" />
                <data android:scheme="content"/>
            </intent-filter>
        </receiver>

    </application>


+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.camerabrowser;

import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.hardware.Usb;
import android.net.Uri;
import android.util.Log;

public class UsbReceiver extends BroadcastReceiver
{
    private static final String TAG = "UsbReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive " + intent);
        if (Usb.ACTION_USB_CAMERA_ATTACHED.equals(intent.getAction())) {
            Uri uri = intent.getData();
            intent = new Intent(context, StorageBrowser.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            try {
                // TODO - add a wrapper to Mtp.Device for this
                int id = Integer.parseInt(uri.getPathSegments().get(1));
                intent.putExtra("device", id);
                context.startActivity(intent);
            } catch (NumberFormatException e) {
                Log.e(TAG, "bad device Uri " + uri);
            }
        }
    }
}
Loading