otanotifier.java
来自「This is a resource based on j2me embedde」· Java 代码 · 共 456 行 · 第 1/2 页
JAVA
456 行
} } } } /** * Posts a status message back to the provider's URL in JAD. * * @param message status message to post * @param url target http url for the status message * @param proxyUsername if not null, it will be put in the post * @param proxyPassword if not null, it will be put in the post * * @exception IOException is thrown if any error prevents the * notification from being successful */ private static void postMsgBackToProvider(String message, String url, String proxyUsername, String proxyPassword) throws IOException { HttpConnection transaction; if (url == null) { return; } transaction = (HttpConnection)Connector.open(url, Connector.WRITE); postMsgBackToProvider(message, transaction, proxyUsername, proxyPassword); } /** * Posts a status message back to the provider's URL in JAD. * * @param message status message to post * @param transaction http connection to use for posting the status message * @param proxyUsername if not null, it will be put in the post * @param proxyPassword if not null, it will be put in the post * * @exception IOException is thrown if any error prevents the * notification from being successful */ private static void postMsgBackToProvider(String message, HttpConnection transaction, String proxyUsername, String proxyPassword) throws IOException { OutputStream out; try { transaction.setRequestMethod(HttpConnection.POST); if (proxyUsername != null && proxyPassword != null) { transaction.setRequestProperty("Proxy-Authorization", formatAuthCredentials(proxyUsername, proxyPassword)); } out = transaction.openOutputStream(); try { int responseCode; out.write(message.getBytes()); responseCode = transaction.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException("Failed to notify " + transaction.getURL() + " HTTP response code: " + responseCode); } } finally { out.close(); } } finally { transaction.close(); } } /** * Formats the username and password for HTTP basic authentication * according RFC 2617. * * @param username for HTTP authentication * @param password for HTTP authentication * * @return properly formated basic authentication credential */ private static String formatAuthCredentials(String username, String password) { byte[] data = new byte[username.length() + password.length() + 1]; int j = 0; for (int i = 0; i < username.length(); i++, j++) { data[j] = (byte)username.charAt(i); } data[j] = (byte)':'; j++; for (int i = 0; i < password.length(); i++, j++) { data[j] = (byte)password.charAt(i); } return "Basic " + Base64.encode(data, 0, data.length); } /** * Retrieves the queued delete notification list. Each element * in the array is a URL to send a delete notification to. * * @return the delete notification list */ private static synchronized PendingNotification[] getDeleteNotifications() { PendingNotification[] array = new PendingNotification[getNumberOfDeleteNotifications()]; if (array.length > 0) { for (int i = 0; i < array.length; i++) { array[i] = new PendingNotification(); } fillDeleteNotificationListForRetry(array); } return array; } /** * Retrieves the number of URLs queued delete in the notification list. * * @return the number of URLs in the delete notification list */ private static native int getNumberOfDeleteNotifications(); /** * Retrieves the queued delete notification list from storage and * increments the retry count of every member of the list. * * @param list empty delete notification list to fill */ private static native void fillDeleteNotificationListForRetry( PendingNotification[] list); /** * Removes the element from the delete notification list. * * @param suiteId suite ID of the notification */ private static native void removeDeleteNotification(int suiteId); /** * Adds an element to the install notification list. * * @param suiteId suite the notification belongs to * @param url url to send the notification to */ private static native void addInstallNotification(int suiteId, String url); /** * Retrieves the URL of suite's install notification from storage and * increments the retry count of element. * * @param suiteId suite ID of the notification * @param dest where to put the notification * * @return true if the notification is found */ private static native boolean getInstallNotificationForRetry( int suiteId, PendingNotification dest); /** * Removes the element from the install notification list. * * @param suiteId suite ID of the notification */ private static native void removeInstallNotification(int suiteId);}/** Executes install reties in the background. */final class InstallRetryHandler implements Runnable { /** Security token of the caller. */ private SecurityToken token; /** MIDlet suite to retry. */ private MIDletSuite suite; /** * Construct a InstallRetryHandler. * * @param theToken security token of the caller * @param theSuite MIDlet suite object */ InstallRetryHandler(SecurityToken theToken, MIDletSuite theSuite) { token = theToken; suite = theSuite; } /** Retries after a short delay. */ public void run() { try { Thread.sleep(OtaNotifier.RETRY_DELAY); } catch (InterruptedException ie) { // ignore } OtaNotifier.retryInstallNotificationInternal(token, suite); }}/** Pending install or delete notification */final class PendingNotification { /** Number of times the record has been retried. */ int retries; /** Suite this notification is for. */ int suiteId; /** URL to post the notification to. */ String url; /** * Returns a debug string. * * @return value of each field in a string */ public String toString() { return "PendingNotification(suite ID = " + suiteId + ", retries = " + retries + ", URL = " + url + ")"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?