コード例 #1
0
    public void run() {
      // 消息循环
      while (true) {
        try {
          String s;
          byte[] recvBuf = new byte[1024];
          DatagramSocket socket = new DatagramSocket(PORT_SERVER);
          DatagramPacket packet = new DatagramPacket(recvBuf, recvBuf.length);
          //                    packet.setData(recvBuf);
          //                    IP = socket.getInetAddress().toString();

          socket.receive(packet);
          s = new String(packet.getData(), 0, packet.getLength());

          Bundle bundle = new Bundle();
          bundle.clear();
          Message msg = new Message();
          msg.what = 0x11;
          bundle.putString("msg", s);
          msg.setData(bundle);
          myHandler.sendMessage(msg); // 向Handler发送消息,更新UI
          socket.close();

        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
コード例 #2
0
ファイル: CommonActivity.java プロジェクト: mondonc/AnCalv2
 public void OpenActivity(int iActivityRequestCode, String sAction, long lRowId) {
   bundleDataStartup.clear();
   bundleDataStartup.putLong(CommonActivity.bundleRowId, lRowId);
   bundleDataStartup.putAll(bundleOtherDataStartup);
   Intent it = new Intent(sAction);
   it.putExtras(bundleDataStartup);
   startActivityForResult(it, iActivityRequestCode);
 }
コード例 #3
0
 /**
  * Clears all the pending metadata changes set since the MediaMetadataEditor instance was created
  * or since this method was last called. Note that clearing the metadata doesn't reset the
  * editable keys (use {@link #removeEditableKeys()} instead).
  */
 public synchronized void clear() {
   if (mApplied) {
     Log.e(TAG, "Can't clear a previously applied MediaMetadataEditor");
     return;
   }
   mEditorMetadata.clear();
   mEditorArtwork = null;
   mMetadataBuilder = new MediaMetadata.Builder();
 }
コード例 #4
0
 public void setStatus(int status, Bundle extras, long updateTime) {
   mStatus = status;
   mStatusUpdateTime = updateTime;
   mExtras.clear();
   if (extras != null) {
     mExtras.putAll(extras);
   }
   mHasStatus = true;
 }
コード例 #5
0
 public int getStatus(Bundle extras) {
   if (mHasStatus) {
     extras.clear();
     extras.putAll(mExtras);
     return mStatus;
   } else {
     return LocationProvider.AVAILABLE;
   }
 }
コード例 #6
0
 @SuppressWarnings("Recycle")
 protected void readSyncState() throws ContactsStorageException {
   @Cleanup("recycle")
   Parcel parcel = Parcel.obtain();
   byte[] raw = getSyncState();
   syncState.clear();
   if (raw != null) {
     parcel.unmarshall(raw, 0, raw.length);
     parcel.setDataPosition(0);
     syncState.putAll(parcel.readBundle());
   }
 }
コード例 #7
0
  public void open() {
    try {
      URL url = new URL(m_url);

      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setReadTimeout(30 * 1000);
      conn.setConnectTimeout(30 * 1000);

      conn.setRequestMethod(m_method);

      if (m_token != null) conn.setRequestProperty("Authorization", m_token);

      if (m_body != null) {
        conn.setFixedLengthStreamingMode(m_body.length);
        conn.setRequestProperty("Content-Type", m_contentType);
        conn.setDoOutput(true);
      }

      if (m_responseListener != null) conn.setDoInput(true);

      if (m_body != null) {
        DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
        wr.write(m_body);
        wr.close();
      }

      Log.d(TAG, m_method + " " + url);

      m_response.clear();
      int resCode = conn.getResponseCode();
      switch (resCode) {
        case HttpURLConnection.HTTP_UNAUTHORIZED:
          if (m_responseListener != null) m_responseListener.onUnauthorized(m_url, m_token);
          else m_response.putString(RESPONSE_UNAUTHORIZED, m_url);
          break;

        default:
          InputStream is = conn.getInputStream();
          if (m_responseListener != null) m_responseListener.onResponse(resCode, is);
          else m_response.putString(RESPONSE_SUCCESS, URLUtils.convertStreamToString(is));
          is.close();
      }

      conn.disconnect();
    } catch (IOException e) {
      e.printStackTrace();
      if (m_responseListener != null) m_responseListener.onError(e);
      else m_response.putString(RESPONSE_ERROR, e.getMessage());
    }
  }
コード例 #8
0
  /**
   * Scrubs Bundles for private serializable subclasses in the extras. If the Bundle's extras
   * contain a private serializable subclass, the Bundle is cleared. If the Bundle is null, has no
   * extras, or the extras do not contain a private serializable subclass, the Bundle is not
   * mutated.
   *
   * @param bundle {@code Bundle} to scrub. This parameter may be mutated if scrubbing is necessary.
   *     This parameter may be null.
   * @return true if the Bundle was scrubbed, false if the Bundle was not modified.
   */
  public static boolean scrub(final Bundle bundle) {
    if (null == bundle) {
      return false;
    }

    /*
     * Note: This is a hack to work around a private serializable classloader attack
     */
    try {
      // if a private serializable exists, this will throw an exception
      bundle.containsKey(null);
    } catch (final Exception e) {
      bundle.clear();
      return true;
    }

    return false;
  }
コード例 #9
0
  public void onDataChange(View view) {

    String newValue = ((EditText) findViewById(R.id.customize_new)).getText().toString();
    String oldValue = ((EditText) findViewById(R.id.customize_old)).getText().toString();

    if (!oldValue.equals(this.givenValue)) {

      Toast.makeText(
              getApplicationContext(),
              getString(R.string.t_customize_invldold) + " " + type,
              Toast.LENGTH_LONG)
          .show();

    } else {

      Intent watchAccIntent = new Intent(getApplicationContext(), WatchAccActivity.class);
      Bundle bundle = getIntent().getBundleExtra("user_details");
      if (bundle != null) {

        String newName = bundle.getString("user_name");
        String newPassword = bundle.getString("user_password");
        String newPhone = bundle.getString("user_phone");
        bundle.clear();

        if (type.equals("Name")) {
          newName = newValue;
        } else if (type.equals("Phone")) {
          newPhone = newValue;
        }

        bundle.putString("user_name", newName);
        bundle.putString("user_password", newPassword);
        bundle.putString("user_phone", newPhone);
      }

      watchAccIntent.putExtra("user_details", bundle);
      startActivity(watchAccIntent);
    }
  }
  @Override
  public void getServerDiffs(
      SyncContext context,
      SyncData baseSyncData,
      SyncableContentProvider tempProvider,
      Bundle extras,
      Object baseSyncInfo,
      SyncResult syncResult) {
    final ContentResolver cr = getContext().getContentResolver();
    mServerDiffs++;
    final boolean syncingSingleFeed = (extras != null) && extras.containsKey("feed");
    if (syncingSingleFeed) {
      String feedUrl = extras.getString("feed");
      getServerDiffsForFeed(context, baseSyncData, tempProvider, feedUrl, baseSyncInfo, syncResult);
      return;
    }

    // select the set of calendars for this account.
    Cursor cursor =
        cr.query(
            Calendar.Calendars.CONTENT_URI,
            CALENDARS_PROJECTION,
            SELECT_BY_ACCOUNT,
            new String[] {getAccount()},
            null /* sort order */);

    Bundle syncExtras = new Bundle();

    boolean refreshCalendars = true;

    try {
      while (cursor.moveToNext()) {
        boolean syncEvents = (cursor.getInt(6) == 1);
        String feedUrl = cursor.getString(3);

        if (!syncEvents) {
          continue;
        }

        // since this is a poll (no specific feed selected), refresh the list of calendars.
        // we can move away from this when we move to the new allcalendars feed, which is
        // syncable.  until then, we'll rely on the daily poll to keep the list of calendars
        // up to date.
        if (refreshCalendars) {
          mRefresh++;
          context.setStatusText("Fetching list of calendars");
          // get rid of the current cursor and fetch from the server.
          cursor.close();
          final String[] accountSelectionArgs = new String[] {getAccount()};
          cursor =
              cr.query(
                  Calendar.Calendars.LIVE_CONTENT_URI,
                  CALENDARS_PROJECTION,
                  SELECT_BY_ACCOUNT,
                  accountSelectionArgs,
                  null /* sort order */);
          // start over with the loop
          refreshCalendars = false;
          continue;
        }

        // schedule syncs for each of these feeds.
        syncExtras.clear();
        syncExtras.putAll(extras);
        syncExtras.putString("feed", feedUrl);
        cr.startSync(Calendar.CONTENT_URI, syncExtras);
      }
    } finally {
      cursor.close();
    }
  }
コード例 #11
0
ファイル: MainActivity.java プロジェクト: nezharen/FileSharer
 private void receiveFile() {
   Client myClient = null;
   Bundle bundle = new Bundle();
   Message msg;
   String filename = "";
   try {
     String cmd = getSocketIn();
     if (cmd != null) {
       String[] s = cmd.split(" ");
       if (s[0].equals(Constants.CLIENT_COMMAND_SEND_FILE + "")) {
         filename = s[1];
         for (int i = 2; i < s.length; i++) filename = filename + " " + s[i];
         status = Constants.SERVER_STATUS_FILE_WAIT_FOR_ACCEPT;
         bundle.putInt(Constants.SERVERS_STATUS, Constants.SERVERS_STATUS_FILE_WAIT_FOR_ACCEPT);
         bundle.putString(Constants.SERVER_HOST, host);
         bundle.putString(Constants.SERVER_FILENAME, filename);
         msg = new Message();
         msg.setData(bundle);
         MainActivity.this.serverMessageHandler.sendMessage(msg);
         while (status == Constants.SERVER_STATUS_FILE_WAIT_FOR_ACCEPT) ;
         if (status != Constants.SERVER_STATUS_FILE_ACCEPTED) {
           putSocketOut(Constants.SERVER_COMMAND_REJECT_FILE + "\n");
           return;
         }
         for (Client client : clients)
           if (client.host.equals(host)) {
             myClient = client;
             break;
           }
         if (myClient == null) {
           putSocketOut(Constants.SERVER_COMMAND_REJECT_FILE + "\n");
           return;
         }
         myClient.status = Constants.CLIENT_STATUS_RECEIVING_FILE;
         bundle.clear();
         bundle.putInt(Constants.CLIENTS_STATUS, Constants.CLIENTS_STATUS_UPDATE_STATUS);
         msg = new Message();
         msg.setData(bundle);
         MainActivity.this.clientMessageHandler.sendMessage(msg);
         Random random = new Random();
         int file_port;
         while (true) {
           file_port = random.nextInt(40000) + 20000;
           if (portAvailable(file_port)) break;
         }
         ServerSocket file_server_socket = new ServerSocket(file_port);
         putSocketOut(Constants.SERVER_COMMAND_ACCEPT_FILE + " " + file_port + "\n");
         Socket file_socket = file_server_socket.accept();
         File path =
             Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
         path.mkdirs();
         File file = new File(path, filename);
         FileOutputStream out = new FileOutputStream(file);
         InputStream in = file_socket.getInputStream();
         byte[] file_buffer = new byte[Constants.BUFFER_SIZE];
         while (true) {
           int count = in.read(file_buffer);
           if (count < 0) break;
           out.write(file_buffer, 0, count);
         }
         out.close();
         file_socket.close();
         file_server_socket.close();
         putSocketOut(Constants.SERVER_COMMAND_RECEIVE_FILE_SUCCESS + "\n");
         myClient.status = Constants.CLIENT_STATUS_RECEIVE_FILE_DONE;
         bundle.putInt(Constants.CLIENTS_STATUS, Constants.CLIENTS_STATUS_RECEIVE_FILE_SUCCESS);
         bundle.putString(Constants.RECEIVED_FILE_PATH, path.getAbsolutePath());
         bundle.putString(Constants.RECEIVED_FILE_NAME, filename);
         msg = new Message();
         msg.setData(bundle);
         MainActivity.this.clientMessageHandler.sendMessage(msg);
       }
     }
   } catch (Exception e) {
     putSocketOut(Constants.SERVER_COMMAND_RECEIVE_FILE_FAILED + "\n");
     if (myClient != null) myClient.status = Constants.CLIENT_STATUS_RECEIVE_FILE_FAILED;
     bundle.putInt(Constants.CLIENTS_STATUS, Constants.CLIENTS_STATUS_RECEIVE_FILE_FAILED);
     bundle.putString(Constants.RECEIVED_FILE_NAME, filename);
     msg = new Message();
     msg.setData(bundle);
     MainActivity.this.clientMessageHandler.sendMessage(msg);
   }
 }
コード例 #12
0
ファイル: CommonActivity.java プロジェクト: mondonc/AnCalv2
 public void SaveDateValuesBeforeChange(Bundle data) {
   if (data != null) data.clear();
 }
コード例 #13
0
ファイル: Linker.java プロジェクト: EliseuTorres/chromium-1
  /**
   * Call this method just after loading all native shared libraries in this process. Note that when
   * in a service process, this will block until the RELRO bundle is received, i.e. when another
   * thread calls useSharedRelros().
   */
  public static void finishLibraryLoad() {
    if (DEBUG) Log.i(TAG, "finishLibraryLoad() called");
    synchronized (Linker.class) {
      if (DEBUG)
        Log.i(
            TAG,
            String.format(
                Locale.US,
                "sInBrowserProcess=%s sBrowserUsesSharedRelro=%s sWaitForSharedRelros=%s",
                sInBrowserProcess ? "true" : "false",
                sBrowserUsesSharedRelro ? "true" : "false",
                sWaitForSharedRelros ? "true" : "false"));

      if (sLoadedLibraries == null) {
        if (DEBUG) Log.i(TAG, "No libraries loaded");
      } else {
        if (sInBrowserProcess) {
          // Create new Bundle containing RELRO section information
          // for all loaded libraries. Make it available to getSharedRelros().
          sSharedRelros = createBundleFromLibInfoMap(sLoadedLibraries);
          if (DEBUG) {
            Log.i(TAG, "Shared RELRO created");
            dumpBundle(sSharedRelros);
          }

          if (sBrowserUsesSharedRelro) {
            useSharedRelrosLocked(sSharedRelros);
          }
        }

        if (sWaitForSharedRelros) {
          assert !sInBrowserProcess;

          // Wait until the shared relro bundle is received from useSharedRelros().
          while (sSharedRelros == null) {
            try {
              Linker.class.wait();
            } catch (InterruptedException ie) {
              // no-op
            }
          }
          useSharedRelrosLocked(sSharedRelros);
          // Clear the Bundle to ensure its file descriptor references can't be reused.
          sSharedRelros.clear();
          sSharedRelros = null;
        }
      }

      if (NativeLibraries.ENABLE_LINKER_TESTS && sTestRunnerClassName != null) {
        // The TestRunner implementation must be instantiated _after_
        // all libraries are loaded to ensure that its native methods
        // are properly registered.
        if (DEBUG) Log.i(TAG, "Instantiating " + sTestRunnerClassName);
        TestRunner testRunner = null;
        try {
          testRunner = (TestRunner) Class.forName(sTestRunnerClassName).newInstance();
        } catch (Exception e) {
          Log.e(TAG, "Could not extract test runner class name", e);
          testRunner = null;
        }
        if (testRunner != null) {
          if (!testRunner.runChecks(sMemoryDeviceConfig, sInBrowserProcess)) {
            Log.wtf(TAG, "Linker runtime tests failed in this process!!");
            assert false;
          } else {
            Log.i(TAG, "All linker tests passed!");
          }
        }
      }
    }
    if (DEBUG) Log.i(TAG, "finishLibraryLoad() exiting");
  }