@@ -190,9 +191,47 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
}
}; + // XBH add patch start :
+ private void setDefaultAccount(ContentResolver cr) {
+ Log.d(TAG, "Set default account");
+ TimeZone timeZone = TimeZone.getDefault();
+ ContentValues value = new ContentValues();
+ value.put(Calendars.NAME, "XBH");
+
+ value.put(Calendars.ACCOUNT_NAME, "xbhgmailaddress@gmail.com");
+ value.put(Calendars.ACCOUNT_TYPE, "com.android.exchange");
+ value.put(Calendars.CALENDAR_DISPLAY_NAME, "XBH");
+ value.put(Calendars.VISIBLE, 1);
+ value.put(Calendars.CALENDAR_COLOR, -9206951);
+ value.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
+ value.put(Calendars.SYNC_EVENTS, 1);
+ value.put(Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
+ value.put(Calendars.OWNER_ACCOUNT, "xbhgmailaddress@gmail.com");
+ value.put(Calendars.CAN_ORGANIZER_RESPOND, 0);
+
+ Uri calendarUri = Calendars.CONTENT_URI;
+ calendarUri = calendarUri.buildUpon()
+ .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
+ .appendQueryParameter(Calendars.ACCOUNT_NAME, "xbhgmailaddress@gmail.com")
+ .appendQueryParameter(Calendars.ACCOUNT_TYPE, "com.android.exchange")
+ .build();
+
+ cr.insert(calendarUri, value);
+ }
+ // XBH add patch end.
+
private class QueryHandler extends AsyncQueryHandler {
public QueryHandler(ContentResolver cr) {
super(cr);
+ // XBH add patch start :
+ Cursor userCursor = cr.query(Calendars.CONTENT_URI, null, null, null, null);
+ if(userCursor != null && userCursor.getCount() == 0) {
+ //setDefaultAccount(cr);
+ Log.d(TAG, "userCursor.getCount() == 0");
+
+ }
+ Log.d(TAG, "userCursor.getCount()" + userCursor.getCount());
+ // XBH add patch end.
}

\packages\providers\CalendarProvider\src\com\android\providers\calendar\CalendarDatabaseHelper.java

    private void insertAccount(SQLiteDatabase db) {
Log.d(TAG, "insertAccount");
TimeZone timeZone = TimeZone.getDefault();
ContentValues value = new ContentValues();
value.put(Calendars.NAME, "XBH11");
value.put(Calendars.ACCOUNT_NAME, "xbhgmailaddress@gmail.com");
Log.i(TAG, "Calendars.ACCOUNT_NAME = " + Calendars.ACCOUNT_NAME);
value.put(Calendars.ACCOUNT_TYPE, "com.android.xbh.tv");
Log.i(TAG, "Calendars.ACCOUNT_TYPE = " + Calendars.ACCOUNT_TYPE);
value.put(Calendars.CALENDAR_DISPLAY_NAME, "XBH");
Log.i(TAG, "Calendars.CALENDAR_DISPLAY_NAME = " + Calendars.CALENDAR_DISPLAY_NAME);
value.put(Calendars.VISIBLE, 1);
Log.i(TAG, "Calendars.VISIBLE = " + Calendars.VISIBLE);
value.put(Calendars.CALENDAR_COLOR, -9206951);
Log.i(TAG, "Calendars.CALENDAR_COLOR = " + Calendars.CALENDAR_COLOR);
value.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
Log.i(TAG, "Calendars.CALENDAR_ACCESS_LEVEL = " + Calendars.CALENDAR_ACCESS_LEVEL);
value.put(Calendars.SYNC_EVENTS, 1);
Log.i(TAG, "Calendars.SYNC_EVENTS = " + Calendars.SYNC_EVENTS);
value.put(Calendars.CALENDAR_TIME_ZONE, timeZone.getID());
Log.i(TAG, "timeZone.getID() = " + timeZone.getID());
value.put(Calendars.OWNER_ACCOUNT, "xbhgmailaddress@gmail.com");
Log.i(TAG, "Calendars.OWNER_ACCOUNT = " + Calendars.OWNER_ACCOUNT);
value.put(Calendars.CAN_ORGANIZER_RESPOND, 0);
Log.i(TAG, "Calendars.CAN_ORGANIZER_RESPOND = " + Calendars.CAN_ORGANIZER_RESPOND); db.insert("Calendars", null, value);
}

或者

   //begin : added by xxx for calendar  demand
private void updateOrInsert(SQLiteDatabase db, String table){
// check this value exsist or not.
String account_name = "Phone";
String account_type = "com.android.huawei.phone";
String calendar_displayName = "Phone";
Integer calendar_color = -12011288;
Integer calendar_access_level = 700;
Integer sync_events = 1;
String calendar_timeZone = "Asia/shanghai";
String ownerAccount = "Phone";
String[] columns = new String[]{"account_name","account_type"," calendar_displayName"};
String selection = " account_name=? and account_type=? and calendar_displayName=? ";
String[] selectionArgs = new String[]{account_name,account_type,calendar_displayName};
boolean alreadyExisted = false; // Cursor cursor = db.query(table, columns, selection, selectionArgs, null, null, null);
Cursor cursor = db.query(table, columns, selection, selectionArgs, null, null, null);
alreadyExisted = (null != cursor) && (cursor.getCount() > 0); /*
* an update statement like this:
* UPDATE secure SET value='com.android.inputmethod.latin/.LatinIME' where name='default_input_method'
* an insert statement like this:
* INSERT INTO secure(name,value) values('default_input_method','com.android.inputmethod.latin/.LatinIME')
*/
String stmt_update = "UPDATE "+table+" SET account_name='" + account_name + "'"+"calendar_displayName='"+ calendar_displayName +"'" + "where account_type='" + account_type + "'";
String stmt_insert = "INSERT INTO "+table+"(account_name,account_type,calendar_displayName,calendar_color,calendar_access_level,sync_events,calendar_timeZone,ownerAccount) values('" +
account_name + "','" + account_type + "','"+calendar_displayName + "','" + calendar_color + "','" + calendar_access_level + "','" + sync_events + "','" + calendar_timeZone + "','" + ownerAccount+ "')";
String stmt = alreadyExisted ? stmt_update : stmt_insert;
db.execSQL(stmt);
}
//end : added by xxx for calendar demand
    private void bootstrapDB(SQLiteDatabase db) {
Log.i(TAG, "Bootstrapping database"); mSyncState.createDatabase(db); createColorsTable(db); createCalendarsTable(db); updateOrInsert(db,"Calendars");
......
}

\packages\providers\CalendarProvider\src\com\android\providers\calendar\CalendarProvider2.java

                        if ((!validAccounts.contains(currAccount)) &&
(!c.getString(1).equalsIgnoreCase("com.android.xbh.tv"))) {
accountsToDelete.add(currAccount);
}
05-18 11:52
查看更多